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?
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.
ls -p | grep -v /
ls -p lets you show / after the folder name, which acts as a tag for you to remove.
Just adding on to carlpett's answer. For a much useful view of the files, you could pipe the output to ls.
find . -maxdepth 1 -type f|ls -lt|less
Shows the most recently modified files in a list format, quite useful when you have downloaded a lot of files, and want to see a non-cluttered version of the recent ones.
{ find . -maxdepth 1 -type f | xargs ls -1t | less; }
added xargs
to make it works, and used -1
instead of -l
to show only filenames without additional ls
info
You can also use ls
with grep
or egrep
and put it in your profile as an alias:
ls -l | egrep -v '^d'
ls -l | grep -v '^d'
"find '-maxdepth' " does not work with my old version of bash, therefore I use:
for f in $(ls) ; do if [ -f $f ] ; then echo $f ; fi ; done