ls (list filenames)

Outputs the names of the files in a directory.

Format:    ls directory_name
Examples:  ls
           ls /home/janet

directory_name is optional. If it's not included, the current directory is assumed.

OptWhat It DoesExample
-1List 1 file per linels -1
-aList all files, including hidden system files
ls -a
.   ..   backup   file1   file2
-dList only directoriesls -d
-lLong listing
ls -l
-rw-r--r--  1  janet  janet     579
2005-1-10 00:22 file1
-rw-r--r--  1  janet  janet     579
2005-1-10 00:22 file2
-rList in reverse order
ls -r
-rw-r--r--  1  janet  janet     579
2005-1-10 00:22 file2
-rw-r--r--  1  janet  janet     579
2005-1-10 00:22 file1
-RList subdirectoriesls -R
-sList with file size in bytes
ls -s
5 file1    3 file2]
-SSort by sizels -S
-XSort by extensionls -X

Get Spring Into Linux® now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.