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.
Opt | What It Does | Example |
---|---|---|
-1 | List 1 file per line | ls -1 |
-a | List all files, including hidden system files |
ls -a . .. backup file1 file2 |
-d | List only directories | ls -d |
-l | Long 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 |
-r | List 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 |
-R | List subdirectories | ls -R |
-s | List with file size in bytes |
ls -s 5 file1 3 file2] |
-S | Sort by size | ls -S |
-X | Sort by extension | ls -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.