CodingNic

Terminal Fundamentals

Listing Files and Flags

Terminal Fundamentals 8 min read

Listing Files and Flags

Objectives

By the end of this chapter, you should be able to:

  • Explain what ls does 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 ls is 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:

bash
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:

text
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:

  1. Run ls in your home directory, then ls -a. What shows up that didn’t before?
  2. Run ls -l. Pick one file and read off its size and last-modified date.
  3. Run ls -la and 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.
  • -a reveals hidden (dot-prefixed) files; -l prints permissions, owner, size, and date for each item; -la does both.

Next up: a set of exercises that pull together everything from this module — navigating, managing files, and now flags.