Search For Answers
How do I list the files in a directory in Linux?
Last updated: March 29, 2011
To list or view the files and contents in a directory in Linux you use the ls command.
The syntax for this command is:
This is the most basic version of this command and will just provide filenames in your current working directory in a linear format. This is ok if you just have a couple files but if you have lots of files it can be difficult to find what you are looking for. Don't worry you have lots of tools at your disposal to display those files and information about them in a variety of ways. To do this you use flags or options to the command and here are a few examples and what they do.
# ls -a (shows all contents in the directory even hidden files that start with a .)
# ls -l (shows the contents in a long list format)
# ls -S (sorts by file size)
# ls -R (lists subdirectories recursively)
# ls -t (sort by modification time)
Now the real power comes when you combine these options. For example if you want to list all the contents in your current directory in a list including hidden from largest to smallest with the sizes in human readable format (-h) use this syntax:
# ls -alhS
For more options check out the manual files:
# man ls