Software & Apps Linux 33 33 people found this article helpful Using the ls Command to List Files in Linux List the files in a directory with this versatile command by Gary Newell Writer Gary Newell was a freelance contributor, application developer, and software tester with 20+ years in IT, working on Linux, UNIX, and Windows. our editorial process Gary Newell Updated on March 09, 2020 VICTOR HABBICK VISIONS / Getty Images Linux Switching from Windows Tweet Share Email The ls command lists the names of the files and folders within the file system. It's one of the most basic, essential commands of the Linux shell. 10 Essential Linux Commands for Navigating Your File System List the Files in a Folder To list all the files in a folder, open a terminal window, select the relevant folder using the cd command, then type: By default, the files and folders are listed in columns across the screen and only display the filename. Hidden files (files with names beginning with a period) are not shown automatically by running the ls command unless you specify the -a or -all switches: ls The -a switch lists every file and folder in the directory. To omit backup files (files ending with a tilde), run the following command: ls -Bls In most cases, the returned list shows the folders in one color and the files as another. If you don't want to show different colors, use the following command: ls To display more detailed output, use the following switch: This provides a list showing the permissions, number of inodes, the owner and the group, the file size, the last accessed date, and time and file name. If you don't want to see the owner, use the following command instead: You can also omit the group details by specifying the following switch: The long format listing works with other switches to show even more information. For example, show the author of the file by running the following command: You can change the output for the long listing to show human readable file sizes as follows: ls -l -hls -l --human-reada Instead of showing the user and group names in a list command, you can get the ls command to show the physical user id and group ids as follows: The ls command can be used to show all of the files and folders from the specified path downwards. For example: The above command shows all of the files and folders below the home directory such as Pictures, Music, Videos, Downloads, and Documents. Combine switches, too. The command ls -aBlh presents a listing as displayed in the screenshot at the top of this section. Change the Output Format By default, the output for the file listing is across the screen in columns. You can, however, specify a format as shown below. To show the list in columns across the screen: ls -Xls -- To show the list in a comma-separated format: ls -mls -- To show the list in a horizontal format: ls -xls --forma To show the list in a long format: ls -lls To show all the files and folders, one on each row: ls -1ls --format=single-columnls --f To show the list vertically: ls -cls --fo How to Sort the Output From the ls Command To sort the output from the ls command use the --sort switch as follows: ls --sort=nonels --sort=sizels --sort=timels -- The default is set to none, which means the files are sorted by name. When you sort by size, the file with the largest size is shown first and the smallest is shown last. Sorting by time shows the file which has been accessed last at the top of the list and the least accessed file is at the bottom of the list. All of the above sorts can be achieved with the following commands instead: ls -Uls -S To show the results in the reverse sort order, use the following command: ls -r --sort=sizels --reverse Shake the Tree An alternative approach to viewing files involves the tree utility, which ships by default with some distributions but not others. When you execute it, you'll see printed to standard output a hierarchy of files and folders.