Find all files in a directory that are not directories themselves
Question
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.
Solution
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
OTHER TIPS
If you need symlinks, pipes, device files and other specific elements of file system to be listed too, you should use:
find -maxdepth 1 -not -type d
This will list everything except directories.
using find is simple as:
find . -maxdepth 1 -type f
find . -type f
find /some/directory -type f
$ find . -type f -print
Each file will be on its own line. You must be in the directory you want to search.
One more option
ls -ltr | grep ^d
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow