ls lists files and directories. It's the command you'll use most often.
Basic Usage
ls
Shows files and folders in the current directory.
Common Options
| Command | What it shows |
|---|---|
ls |
Files and folders |
ls -l |
Long format with details |
ls -a |
All files, including hidden |
ls -la |
Both: details + hidden |
ls -lh |
Human-readable sizes |
Long Format (-l)
ls -l
Output:
-rw-r--r-- 1 john staff 1024 Dec 15 10:30 file.txt
drwxr-xr-x 3 john staff 96 Dec 14 09:15 folder
What each column means:
| Column | Meaning |
|---|---|
-rw-r--r-- |
Permissions |
1 |
Number of links |
john |
Owner |
staff |
Group |
1024 |
Size in bytes |
Dec 15 10:30 |
Last modified |
file.txt |
Name |
The first character: - for file, d for directory.
Show Hidden Files (-a)
ls -a
Shows everything, including files starting with .:
. .. .zshrc .gitignore Documents file.txt
Human-Readable Sizes (-h)
ls -lh
Shows sizes as K, M, G instead of bytes:
-rw-r--r-- 1 john staff 1.2M Dec 15 10:30 video.mp4
-rw-r--r-- 1 john staff 256K Dec 14 09:15 image.png
Sort Options
ls -lt # Sort by time (newest first)
ls -ltr # Sort by time (oldest first)
ls -lS # Sort by size (largest first)
List Specific Directory
ls ~/Downloads
ls /usr/local/bin
List Multiple Locations
ls ~/Documents ~/Downloads
One File Per Line
ls -1
Useful for scripting.
Show Only Directories
ls -d */
Colorized Output
ls -G
Colors help distinguish files from folders. Make it permanent:
echo 'alias ls="ls -G"' >> ~/.zshrc
source ~/.zshrc
Common Combinations
# The everyday command
ls -la
# With human-readable sizes
ls -lah
# Newest files at bottom
ls -latr
# Largest files first
ls -lahS
My Favorite Alias
Add to ~/.zshrc:
alias ll="ls -lah"
Now just type ll for a full listing.
What ls Can't Do
For more complex file finding:
- Find files by name: use
find - Search file contents: use
grep - Recursive listing: use
findorls -R
Recursive Listing
ls -R
Lists all subdirectories too. Can be overwhelming in large folders.
Quick Reference
| Command | Result |
|---|---|
ls |
List files |
ls -l |
Detailed list |
ls -a |
Include hidden |
ls -la |
Detailed + hidden |
ls -lh |
Human sizes |
ls -lt |
Sort by time |
ls -1 |
One per line |
Keep Learning
ls is the first command everyone learns. The free course builds from here to more powerful commands.
Check it out at Mac Terminal for Humans.