ls system
you've been typing 'ls' for years and you know two flags.
The ls man page is 800 lines long. You have been typing ls and occasionally ls -l since the first day you opened a terminal. That’s like owning a car for ten years and only using first gear.
This page isn’t about whether you should use ls. You already use ls. Every day. Multiple times. You cd into a directory and you ls. It’s muscle memory. It’s practically a tic. You probably ls after ls sometimes, just to make sure the files are still there. They are. They haven’t moved.
The problem is you’ve been using about 3% of what ls can do. You list files. You see names. Sometimes you use -l for the “long” format and feel advanced. Meanwhile ls has been sitting there with dozens of flags that would save you time, and you’ve never asked.
We’re fixing that today.
Unless you’re running Windows then wtf none of this applies to you. But hey, come to the dark side, go install WSL2 and you can follow along. We’ll wait. Impatiently.
If you’re lazy like me (all sysadmins are!) then click here for the ls cheat sheet.
The only command you’ve been using
ls
Files and folders. Alphabetical. No details. No sizes. No dates. Just names. You’ve been looking at a directory listing with less information than a restaurant receipt.
The one you should actually be using
ls -lah
This is the upgrade you didn’t know you needed.
drwxr-xr-x 5 owner owner 4.0K Mar 14 09:22 .
drwxr-xr-x 12 owner owner 4.0K Mar 13 16:40 ..
-rw-r--r-- 1 owner owner 18K Mar 14 09:22 report.pdf
drwxr-xr-x 3 owner owner 4.0K Mar 12 11:15 src/
-rwxr-xr-x 1 owner owner 2.1M Mar 10 14:33 binary
-rw-r--r-- 1 owner owner 412 Mar 9 08:17 .gitignore
lrwxrwxrwx 1 owner owner 11 Mar 8 22:01 link -> /etc/hosts
Permissions. Owner. Size in human-readable units (not bytes — nobody thinks in bytes). Modified date. Hidden files. Everything. One command.
What each flag does
-l— long format (permissions, owner, size, date)-a— show all files, including hidden ones (dotfiles)-h— human-readable sizes (4.0K, 18K, 2.1M instead of 4096, 18432, 2097152)
You want this to be your default? Alias it:
alias ll='ls -lah'
Put that in your ~/.bashrc and now ll does what ls should have done in the first place.
Sort by time (most recent first)
ls -laht
Newest files on top. This is how you answer “what changed recently?” without opening a file manager and clicking a column header three times because it sorted ascending first.
ls -lahtr
Add -r to reverse it — oldest first. Useful when you want to find ancient files lurking in a directory.
Sort by size (biggest first)
ls -lahS
Capital -S. Biggest files on top. For when you’re out of disk space and need to find what’s eating it.
ls -lahSr
Reversed — smallest first. Less useful, but it exists.
List only directories
ls -d */
Just the directories. No files. For when a directory has 4,000 files and you only care about the folder structure.
Recursive listing (everything, all the way down)
ls -R
Every file in every subdirectory. This will flood your terminal if you run it in your home directory. You’ve been warned.
For a better tree view, use tree if it’s installed:
tree -L 2
Two levels deep. Nicely formatted. Won’t make you scroll for forty-five minutes.
One file per line
ls -1
That’s the number one, not a lowercase L. One file per line. Useful when you’re piping ls output to another command:
ls -1 *.log | wc -l
Count the log files. No parsing multi-column output. Clean.
Show file types at a glance
ls -F
Appends indicators: / for directories, * for executables, @ for symlinks. Instantly tells you what’s what without checking permissions.
bin/ config.yml deploy* logs/ readme.md latest@
Directories have slashes. deploy is executable. latest is a symlink. You didn’t have to check any of them individually.
Only show certain files
You don’t need to list everything. Use globs:
ls -lah *.log
ls -lah *.{jpg,png,gif}
ls -lah src/*.go
List specific files by pattern. Your file manager would make you type in a search bar, wait for it to index, and then show you results from 6 different directories you didn’t ask about.
The flags that actually matter
| Flag | What it does |
|---|---|
-l |
Long format — permissions, owner, size, date. |
-a |
Show all files including hidden (dotfiles). |
-A |
Show almost all — hidden files but skip . and ... |
-h |
Human-readable sizes (K, M, G). |
-t |
Sort by modification time, newest first. |
-S |
Sort by size, largest first. |
-r |
Reverse sort order. |
-R |
Recursive — list subdirectories too. |
-d |
List directories themselves, not their contents. |
-1 |
One entry per line. |
-F |
Append type indicators (/ * @ =). |
--color |
Colorize output by file type. Usually on by default. |
-i |
Show inode numbers. For when things get serious. |
“But my file manager—”
Oh, you mean Nautilus? Finder? Windows Explorer? The thing that takes three seconds to open, indexes your entire drive in the background, uses 200MB of RAM to show you a folder, and crashes if you open a directory with too many files? Let’s talk about that.
“I can see thumbnails.” You’re listing files, not browsing a photo gallery. If you need thumbnails, use a photo viewer. If you need to know what files are in a directory, ls -lah takes 0.002 seconds and doesn’t need to render 47 JPEG previews.
“I can drag and drop.” Drag and drop what? Files from one folder to another? mv file.txt /dest/. Done. No mouse required. No accidentally dropping it into the wrong folder because your hand twitched. No “Undo Move” because you dragged it into a hidden .Trash folder.
“Finder shows me file sizes.” Finder shows you “4 KB” for a 4,096-byte file and “–” for directories unless you right-click, Get Info, wait for it to calculate, and then it tells you “243 items, 1.2 GB.” du -sh folder/ does that instantly. Or ls -lahS sorts everything by size in one shot.
“Windows Explorer has a search bar.” Windows Explorer’s search uses Windows Search Indexing, which runs in the background consuming CPU and disk I/O so that when you eventually search for something, it might find it. Or it might not. It’s unpredictable. ls *.pdf doesn’t need an index. It doesn’t need a service. It doesn’t need to restart.
“I can sort by clicking column headers.” And then you click the wrong one and it sorts by “Date Created” instead of “Date Modified” and you don’t notice for ten minutes. ls -laht sorts by modification time, every time, and it doesn’t have a column header to accidentally click.
ls cheat sheet
You made it. Or you skipped straight here. Either way, no judgment. Copy and paste these. Pin them. Tattoo them on your forearm. Whatever works.
| What you’re doing | Command |
|---|---|
| List with all details | ls -lah |
| Sort by time (newest first) | ls -laht |
| Sort by time (oldest first) | ls -lahtr |
| Sort by size (biggest first) | ls -lahS |
| Only directories | ls -d */ |
| One file per line | ls -1 |
| Show file types | ls -F |
| Recursive listing | ls -R |
| Specific file types | ls -lah *.log |
| Count files | ls -1 *.log | wc -l |
| Tree view (if installed) | tree -L 2 |
The one alias:
alias ll='ls -lah'— put it in your~/.bashrcand never type a barelsagain.