C.W.K.
Stream
Lesson 03 of 12 · published

ls Power Flags

~12 min · ls, flags, macos

Level 0Window Tourist
0 XP0/95 lessons0/14 achievements
0/100 XP to next level100 XP to go0% complete

Beyond -lah

You already know the long-all-human combo. Here's what else ls can do without reaching for find.

Sorting

  • -t — by modification time. Newest first.
  • -tr — newest at the bottom. Pairs perfectly with tail: ls -tr | tail = the most recently changed.
  • -S — by size, biggest first. ls -lhS | head is your "what's eating my disk" one-liner.
  • -X (GNU) — by extension

Display

  • -1 — one entry per line. Pipe-friendly.
  • -F — append / to dirs, * to executables, @ to symlinks.
  • -d — list directories themselves, not their contents. ls -d */ = just the subdirectory names.
  • -i — show inode numbers (for hard-link spotting).
  • -G (BSD) / --color=auto (GNU) — colorize.

Hidden vs almost-all

-a includes . (current dir) and .. (parent dir). Most days you want -A instead — every dotfile except those two.

Time precision

Default ls -l shows year for old files and time for recent. ls -l --time-style=full-iso (GNU) gives ISO-8601 timestamps. On macOS BSD ls, use ls -lT for a fully expanded timestamp.

Code

What's eating my disk?·bash
ls -lhS ~/Downloads | head
# Largest directories
du -sh * 2>/dev/null | sort -h | tail
Just the subdirectories·bash
ls -d */
# With dotfile dirs included
ls -d .*/ */ 2>/dev/null

External links

Exercise

In your home directory, run ls -tr | tail, ls -lhS | head, ls -d */, ls -lA. Notice how each answers a different question. Combine: ls -lhSr ~/Downloads | tail — biggest downloads at the bottom.

Progress

Progress is local-only — sign in to sync across devices.
Spotted a bug or have feedback on this page?Report an Issue

Comments 0

🔔 Reply notifications (sign in)
Sign inPlease sign in to comment.

No comments yet — be the first.