Listing Files and Flags
Objectives
By the end of this chapter, you should be able to:
- Explain what
lsdoes and why you’d reach for a flag - Define what a flag is and how flag syntax works
- List files with more detail using
-a,-l, and-la
💡 Why this matters: Bare
lsis fine for a quick look, but you’ll spend a lot of your career checking permissions, hunting for hidden config files, and reading detailed file listings. The flags in this lesson are what unlock that information.
A Quick Recap of ls
You’ve already used ls to list whatever’s in your current directory. Run it in your home directory and you’ll typically see folders like Desktop, Documents, and Downloads — but plain ls is only showing you part of the picture.
What’s a Flag?
You saw your first flag back in the last lesson: the -r in cp -r. A flag is an option you attach to a command, written with a leading -, that changes how the command behaves. Most flags are a single letter, and you can stack several of them behind one dash — -la runs ls with both the -l and -a flags at once.
Revealing Hidden Files with -a
Any file or folder whose name starts with a . is hidden by default — things like .bash_history or .gitconfig live in your home directory right now, but plain ls won’t show them. Add -a (“all”) and they appear:
ls -a
Getting Detail with -l
-l switches ls into “long” format, printing one line per item with real detail instead of just a name. A long listing looks like this:
drwxr-xr-x 5 sam staff 160 Jul 14 09:12 Desktop
-rw-r--r-- 1 sam staff 1024 Jul 10 15:03 resume.docx
Left to right: permissions, owner, file size, last modified date, and name. You’ll go much deeper on that permissions column in the next module — for now, just know -l is where that information lives.
Quick Reference
| Flag | Shows |
|---|---|
-a |
Hidden files (names starting with .) |
-l |
One line per item, with permissions, owner, size, and date |
-la |
Both at once |
Try It
ls and its flags run against your real filesystem, so try these in your own terminal rather than a sandbox:
- Run
lsin your home directory, thenls -a. What shows up that didn’t before? - Run
ls -l. Pick one file and read off its size and last-modified date. - Run
ls -laand confirm it’s just the combination of the two.
Recap
- Flags are options attached to a command with
-, and you can stack several behind one dash. -areveals hidden (dot-prefixed) files;-lprints permissions, owner, size, and date for each item;-ladoes both.
Next up: a set of exercises that pull together everything from this module — navigating, managing files, and now flags.