How can I make ls only display files?

I figure there has to be a way of making ls only display non-directories, but the man page doesn't make it obvious


ls -p | grep -v /

Using ls -p tells ls to append a slash to entries which are a directory, and using grep -v / tells grep to return only lines not containing a slash.


You may try this:

find . -maxdepth 1 -not -type d

And map this to a special alias.

But if you're really keen on using the ls command, here:

ls -p | egrep -v /$


Alternatively:

ls -lAh | grep -v '^d'

This method lists in

  • -l Long list format
  • -A Displays almost all (show hidden files but don't show . and ..)
  • -h Human readable file sizes

while grep

  • -v Don't show matching records
  • Regular expression filter ^d - Those start with letter d (for directory) i.e drwxrwxr-x <some file details> <foldername>

If you don't want to type every time, you may make it into an alias for your bash/shell profile.