Software & Apps Linux Using the ls Command to List Files in Linux List the files in a directory with this versatile command Share Pin Email Print VICTOR HABBICK VISIONS / Getty Images Linux Switching from Windows 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 December 09, 2019 30 30 people found this article helpful 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 and select the relevant folder using the cd command then type: ls By default, the files and folders will be listed in columns across the screen and all you will see is 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 -als --all This -a switch lists every file and folder within the directory. To omit backup files (files ending with a tilde), run the following command: ls -Bls --ignore-backups 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, you can use the following command: ls --color=never To display more detailed output, use the following switch: ls -l 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: ls -g You can also omit the group details by specifying the following switch: ls -o 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: ls -l --author You can change the output for the long listing to show human readable file sizes as follows: ls -l -hls -l --human-readablels -l -s 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: ls -l -n The ls command can be used to show all of the files and folders from the specified path downwards. For example: ls -R /home The above command will show 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. ls -Xls --format=across Shows the list in columns across the screen. ls -mls --format=commas Shows the list in a comma separated format. ls -xls --format=horizontal Shows the list in a horizontal format. ls -lls --format=long Shows the list in a long format. ls -1ls --format=single-columnls --format=verbose Shows all the files and folders, one on each row. ls -cls --format=vertical Shows the list vertically. 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 --sort=version 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 first and the least accessed file last. All of the above sorts can be achieved with the following commands instead: ls -Uls -Sls -tls -v To show the results in the reverse sort order use the following command: ls -r --sort=sizels --reverse --sort=size 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.