ls lists what is in a directory. It is one of the commands you will use most, because it shows you what you are working with.
Basic listing
$ ls
Documents Downloads notes.txtWith no argument, ls shows the current directory. Give it a path to look elsewhere without moving there:
$ ls /etc/aptColours depend on your settings. Many distributions set up an alias that adds them.
Hidden files
Names that start with a dot are hidden from a plain listing. Use -a to show everything:
$ ls -a
. .. .bashrc Documents Downloads notes.txt. is the directory itself and .. is its parent. -A shows hidden files but leaves those two out. Hiding is a way to reduce clutter, not a security feature.
Long format
-l shows one entry per line with details:
$ ls -l
total 8
drwxr-xr-x 2 pete pete 4096 Nov 20 09:15 Documents
-rw-r--r-- 1 pete pete 120 Nov 21 17:02 notes.txtFrom left to right: type and permissions, link count, owner, group, size in bytes, last modification time, name. The first character is the type: d for a directory, - for a regular file, l for a symbolic link. The total line counts disk blocks used by the listed files.
Useful options
Options can be combined, so ls -la means -l and -a together.
-hwith-lprints sizes such as4.0Kor2.5M.-tsorts by modification time, newest first.-rreverses the order.-Rlists subdirectories too.-dshows a directory itself instead of its contents.
$ ls -ld Documents
drwxr-xr-x 2 pete pete 4096 Nov 20 09:15 DocumentsGNU ls on Linux and the BSD ls on macOS share these short options, though colour settings and date formats differ.
The shell navigation lab is a good place to explore listings.
Try it
- Run
lsand thenls -ain your home directory. - Run
ls -lh /var/log. - Find the newest file with
ls -lt. - Compare
ls /tmpwithls -ld /tmp.
Check your understanding
ls (List Directories)
All 5 sections ยท no timer
Unlimited retries
Questions from every section are combined into one assessment. Answer them all correctly to complete the article.
Your completion saves in this browser. Sign in to sync it to your account.