ls - Looking Around
ls lists directory contents. It's probably the command you'll run most often.
Basic Usage
By default, ls shows the contents of your current directory, names only, sorted alphabetically.
ls with a Path
Specify a directory to list its contents:
The Essential Flags
-l (Long Format)
This is the flag you'll use most:
Each column means:
- Permissions (
drwxr-xr-x) - Link count (number of hard links)
- Owner (user)
- Group (user)
- Size (in bytes)
- Modified date
- Name
First Character
The first character tells you the type:
d= directory-= regular filel= symbolic link
-a (All Files)
Shows hidden files (those starting with .):
Hidden files are everywhere in Linux - configs, caches, history files. You need -a to see them.
-h (Human Readable)
Makes file sizes readable:
Instead of 1048576, you see 1.0M. Much better.
Understanding Colors
Most terminals color-code ls output:
| Color | Meaning |
|---|---|
| Blue | Directory |
| Green | Executable file |
| Cyan | Symbolic link |
| Red | Broken link or archive |
| Yellow | Device file |
| Magenta | Image/media file |
| White/Default | Regular file |
Color-Coded Context
When you see blue, you know you can cd into it. Green means you can run it with ./filename. This visual feedback helps you work faster.
Combining Flags
Flags can be combined:
ls -lah is so common it's worth memorizing as a single unit: "ell-ay-aitch."
My Go-To
I use ls -lah probably 50 times a day. It shows everything: hidden files, permissions, human-readable sizes. Make it muscle memory.
Other Useful Flags
-t (Sort by Time)
Most recently modified first:
-r (Reverse)
Reverse the sort order:
-S (Sort by Size)
Largest files first:
-R (Recursive)
List subdirectories too:
Quick Reference
| Command | What It Shows |
|---|---|
ls | Basic list |
ls -l | Long format with details |
ls -a | Include hidden files |
ls -la | All files with details |
ls -lah | All files, details, human sizes |
ls -lt | Sort by modification time |
ls -lS | Sort by size |
ls -R | Recursive listing |
Listing Specific Files
Use wildcards to filter:
Which command shows ALL files (including hidden) with detailed info and human-readable sizes?
Key Takeaways
lsshows directory contents-lgives detailed (long) format-aincludes hidden files-hmakes sizes human-readablels -lahis your new best friend-tsorts by time,-Ssorts by size
Next: cd - how to actually move around the file system.