ls – list directory contents

ls lists directory contents. It’s the most commonly used command for seeing what files and directories exist in a location.
Synopsis
ls [OPTIONS] [FILE...]
Common Options
| Option | Description |
|---|---|
-l | Long format (permissions, owner, size, date) |
-a | Show all files including hidden (dotfiles) |
-h | Human-readable sizes (KB, MB, GB) |
-R | Recursive listing |
-t | Sort by modification time (newest first) |
-S | Sort by file size (largest first) |
-r | Reverse sort order |
-d | List directories themselves, not contents |
-1 | One file per line |
-F | Append indicator (/ for dirs, * for executables) |
Examples
Basic listing
$ ls
ansible bash projects scripts documents
Long format with human-readable sizes
$ ls -lh
total 24K
drwxr-xr-x 5 greys staff 4.0K Jan 15 10:30 ansible
drwxr-xr-x 3 greys staff 4.0K Jan 14 09:15 bash
drwxr-xr-x 12 greys staff 4.0K Jan 15 14:22 projects
Show hidden files
$ ls -la
total 48K
drwxr-xr-x 10 greys staff 4.0K Jan 15 14:30 .
drwxr-xr-x 3 root root 4.0K Jan 10 08:00 ..
-rw-r--r-- 1 greys staff 220 Jan 10 08:00 .bashrc
drwxr-xr-x 5 greys staff 4.0K Jan 15 10:30 ansible
Sort by time (newest first)
$ ls -lt
total 24K
drwxr-xr-x 12 greys staff 4.0K Jan 15 14:22 projects
drwxr-xr-x 5 greys staff 4.0K Jan 15 10:30 ansible
drwxr-xr-x 3 greys staff 4.0K Jan 14 09:15 bash
Sort by size (largest first)
$ ls -lhS
total 1.2G
-rw-r--r-- 1 greys staff 800M Jan 15 10:00 backup.tar.gz
-rw-r--r-- 1 greys staff 350M Jan 14 15:30 database.sql
-rw-r--r-- 1 greys staff 50M Jan 13 09:00 logs.txt
List specific file types
$ ls *.pdf
document.pdf report.pdf manual.pdf
List directories only
$ ls -d */
ansible/ bash/ projects/ scripts/
One file per line
$ ls -1
ansible
bash
projects
scripts
Show Symlinks
Use ls -l to see where symbolic links point:

$ ls -l /usr/bin/python
lrwxrwxrwx 1 root root 9 Jan 10 08:00 /usr/bin/python -> python3.9
Show SELinux Contexts
On SELinux-enabled systems, use -Z to show security contexts:

$ ls -lZ /var/www/html
-rw-r--r--. root root unconfined_u:object_r:httpd_sys_content_t:s0 index.html
Understanding ls -l Output
-rw-r--r-- 1 greys staff 4096 Jan 15 10:30 file.txt
│└──┬───┘ │ └─┬─┘ └─┬─┘ └─┬┘ └────┬─────┘ └──┬───┘
│ │ │ │ │ │ │ └─ filename
│ │ │ │ │ │ └─ modification date
│ │ │ │ │ └─ size in bytes
│ │ │ │ └─ group
│ │ │ └─ owner
│ │ └─ link count
│ └─ permissions (rwx for user, group, others)
└─ file type (- file, d directory, l symlink)
Tips
- Combine options:
ls -lahfor full details with hidden files - Colorized output: Most modern systems enable
--color=autoby default - Add to .bashrc:
alias ll='ls -lah'for quick access - macOS: Use
-Gfor color (instead of--color) - Check if file exists:
ls filename 2>/dev/null && echo "exists"
See Also
Related Commands
- cd — Change directory
- pwd — Print working directory
- find — Search for files
- chmod — Change file permissions






