How to list only files and not directories of a directory Bash?

Rodrigo picture Rodrigo · May 13, 2012 · Viewed 138.2k times · Source

How can I list all the files of one folder but not their folders or subfiles. In other words: How can I list only the files?

Answer

carlpett picture carlpett · May 13, 2012

Using find:

find . -maxdepth 1 -type f

Using the -maxdepth 1 option ensures that you only look in the current directory (or, if you replace the . with some path, that directory). If you want a full recursive listing of all files in that and subdirectories, just remove that option.