The ls command lists the contents of a directory. It’s one of the first commands every Linux user learns—and one of the most useful, because a handful of options turn a plain file list into a powerful inspection tool.
Here are 6 practical ways to use ls, each with examples and output.
Table of Contents
1. List files in long format with ls -l
By default, ls just prints names in columns:
ls
0001.pcap anaconda-ks.cfg Desktop notes.txt
Add -l (long format) to see permissions, owner, group, size, and modification time:
ls -l
total 176
-rw-r--r--. 1 root root 683 Aug 19 09:59 0001.pcap
-rw-------. 1 root root 1586 Jul 31 02:17 anaconda-ks.cfg
drwxr-xr-x. 2 root root 4096 Jul 31 02:48 Desktop
-rw-r--r--. 1 root root 245 Sep 8 10:12 notes.txt
Reading the columns from left to right:
| Column | Meaning |
|---|---|
-rw-r--r-- | File type and permissions |
1 | Number of hard links |
root root | Owner and group |
683 | Size in bytes |
Aug 19 09:59 | Last modification time |
0001.pcap | File name |
The very first character tells you the type: - is a regular file, d is a directory, and l is a symbolic link.
2. Show human-readable file sizes with ls -lh
Sizes in raw bytes are hard to read. The -h option converts them to KB, MB, and GB:
ls -lh
total 176K
-rw-r--r--. 1 root root 683 Aug 19 09:59 0001.pcap
-rw-------. 1 root root 1.6K Jul 31 02:17 anaconda-ks.cfg
drwxr-xr-x. 2 root root 4.0K Jul 31 02:48 Desktop
-rw-r--r--. 1 root root 245 Sep 8 10:12 notes.txt
1586 becomes 1.6K—much easier to scan. This is the quickest way to check file size in Linux.
3. Show hidden files with ls -a
Files whose names begin with a dot (.) are hidden by default. Use -a to reveal them:
ls -a
. .. .bashrc .ssh 0001.pcap anaconda-ks.cfg Desktop notes.txt
Combine with -l for details, or use -A to hide the . and .. entries:
See also: Mastering the Linux Command Line — Your Complete Free Training Guide
ls -alh
total 192K
drwx------. 4 root root 4.0K Sep 8 10:12 .
drwxr-xr-x. 3 root root 4.0K Jul 31 02:10 ..
-rw-r--r--. 1 root root 571 Jul 31 02:17 .bashrc
drwx------. 2 root root 4.0K Aug 02 08:30 .ssh
-rw-r--r--. 1 root root 683 Aug 19 09:59 0001.pcap
See also how to list hidden files in Linux.
4. Sort files by size with ls -lS
The -S option sorts by size, largest first—handy for finding what’s taking up space:
ls -lhS
total 176K
drwxr-xr-x. 2 root root 4.0K Jul 31 02:48 Desktop
-rw-------. 1 root root 1.6K Jul 31 02:17 anaconda-ks.cfg
-rw-r--r--. 1 root root 683 Aug 19 09:59 0001.pcap
-rw-r--r--. 1 root root 245 Sep 8 10:12 notes.txt
Add -r to reverse it (smallest first):
ls -lhSr
More on this in sorting ls command output by file size.
5. Sort files by modification time with ls -lt
The -t option sorts by modification time, newest first—useful for spotting recently changed files:
ls -lt
total 176
-rw-r--r--. 1 root root 245 Sep 8 10:12 notes.txt
-rw-r--r--. 1 root root 683 Aug 19 09:59 0001.pcap
drwxr-xr-x. 2 root root 4096 Jul 31 02:48 Desktop
-rw-------. 1 root root 1586 Jul 31 02:17 anaconda-ks.cfg
A very common combination is -lrt, which puts the newest files last—perfect when watching a log directory, because the most recent entries appear right above your prompt:
ls -lrt /var/log
See sorting ls output by time.
6. List directories recursively with ls -R
To see the contents of a directory and all its subdirectories, use -R:
ls -R projects
projects:
app docs
projects/app:
main.py utils.py
projects/docs:
readme.md
If you only want the directory itself (not its contents), use -d:
ls -ld /var/log
drwxr-xr-x. 12 root root 4096 Sep 8 09:00 /var/log
This is the correct way to inspect a directory’s own permissions and size rather than listing what’s inside it.
Bonus: show inode numbers with ls -i
Every file has an inode—the structure holding its metadata and data location. -i displays it:
ls -li notes.txt
2621501 -rw-r--r--. 1 root root 245 Sep 8 10:12 notes.txt
This is how you confirm two names are hard links to the same file: identical inode numbers mean identical data.
Summary
| Goal | Command |
|---|---|
| Long format (details) | ls -l |
| Human-readable sizes | ls -lh |
| Include hidden files | ls -a or ls -alh |
| Sort by size (largest first) | ls -lhS |
| Sort by time (newest first) | ls -lt (or -lrt for newest last) |
| Recursive listing | ls -R |
| The directory itself | ls -ld dirname |
| Show inode numbers | ls -li |
Most of these options combine freely—ls -lahSr is perfectly valid. Once ls -lh, ls -lrt, and ls -la are in your muscle memory, you’ll navigate the filesystem far faster. For a fuller reference, see understanding the ls command in Linux.



