Find all files in a directory that are not directories themselves

Alex picture Alex · Aug 19, 2009 · Viewed 38.4k times · Source

I am looking for a way to list all the files in a directory excluding directories themselves, and the files in those sub-directories.

So if I have:

./test.log
./test2.log
./directory
./directory/file2

I want a command that returns: ./test.log ./test2.log and nothing else.

Answer

John Kugelman picture John Kugelman · Aug 19, 2009

If you want test.log, test2.log, and file2 then:

find . -type f

If you do not want file2 then:

find . -maxdepth 1 -type f