open atlas
↑ Back to track
Command line CLI · 01 · 02

The prompt and commands

A shell command has three parts: the program name, optional flags that change behaviour, and arguments that say what to act on. Learning to read and compose this grammar unlocks every command-line tool.

CLI Foundations ◷ 18 min
Level
FoundationsJuniorMiddleSenior

Every shell command follows the same grammar: a name, then some switches, then targets. Once you see the pattern, any new command becomes readable on first sight — even one you have never used before. Before that click, commands look like line noise.

By the end of this lesson you can decompose any command into its program name, flags, and arguments, and you can explain what ls, ls -l, and ls -la each do.

Goal

After this lesson you can identify the three parts of a shell command (program, flags, arguments), read the output of ls -l, and compose simple variations by combining flags.

1

A shell command starts with the program name. When you type ls and press Enter, the shell looks for a program called ls on the system, runs it, and prints its output. The first word on a command line is always the program (or shell built-in) to execute. Everything that follows modifies or directs that program.

ls

ls with no extras lists the names of files and directories in the current directory, one after another, in alphabetical order.

2

Flags (options) change how the program behaves. A flag is a short word starting with - (a single dash for single-letter flags) or -- (two dashes for long-form flags). Flags come after the program name, before the arguments. They are optional: without them the command uses its defaults.

ls -l

The -l flag (“long”) tells ls to show one entry per line with extra detail: permissions, owner, size, and modification date. The program name (ls) is unchanged; the flag modifies the output format.

3

Multiple single-letter flags can be combined after one dash. Instead of writing -l -a you can write -la. Order within the cluster usually does not matter.

ls -la

-a means “all” — include hidden files (files whose names start with .). Combined, -la gives you the long format and shows hidden files. You will see entries like .bashrc and .ssh that a plain ls silently omits.

4

Arguments tell the program what to act on. An argument is a path, a filename, or any other target that comes after the flags. Without an argument, many commands default to the current directory.

ls -l /etc

Here /etc is the argument: list the contents of /etc in long format instead of the current directory. A command can take zero, one, or many arguments depending on what the program accepts.

Worked example

Reading ls -la output.

Running ls -la in a home directory might produce:

total 48
drwxr-xr-x  6 alice alice 4096 Jun 20 09:14 .
drwxr-xr-x 32 root  root  4096 Jun 18 17:00 ..
-rw-r--r--  1 alice alice  220 Jun 18 17:00 .bash_logout
-rw-r--r--  1 alice alice 3526 Jun 18 17:00 .bashrc
drwxrwxr-x  2 alice alice 4096 Jun 20 08:55 projects

Reading one line: -rw-r--r-- 1 alice alice 3526 Jun 18 17:00 .bashrc

  • -rw-r--r-- — permissions: the leading - means it is a regular file; rw- = owner can read+write; r-- = group can read; r-- = others can read.
  • 1 — number of hard links.
  • alice alice — owner and group.
  • 3526 — size in bytes.
  • Jun 18 17:00 — last modification date and time.
  • .bashrc — file name (starts with ., so it is hidden from plain ls).
Why this works

The POSIX standard defines the convention that single-letter flags use one dash (-l) and long descriptive flags use two dashes (--long). Most Linux commands follow this. Some older or non-POSIX tools (like find) use a single dash for long flags (-name). When a command confuses you, run man ls (the manual page) or ls --help to see its exact flag syntax.

Common mistake

Putting a space inside a flag cluster breaks it: -l -a is fine; -l -a with an extra space between them is also fine; but -l a (no dash before a) would pass the literal string a as an argument to ls, not as a flag — and ls would try to list a file named a.

Check yourself
Quiz

Which command lists all files (including hidden ones) in long format for the directory /var/log?

Recap

Every shell command follows the same grammar: program name, then flags (single-dash single-letter like -l, or double-dash long-form like --all), then arguments (paths or targets to act on). ls lists the current directory; ls -l adds per-file detail; ls -la also reveals hidden files. Flags can be clustered (-la = -l -a). Once you see this grammar, every new command is just a new program name — the flag and argument pattern stays the same.

Practice

Start at the top. Tasks go easiest → hardest: recall a fact, apply it to a case, then a senior-level stretch. Open one, attempt it, then reveal.

recallapplystretch0 of 5 done

Something unclear?

Ask a question about this lesson. Questions are anonymous and go straight to the author to make the lesson better.

shortcuts expand
search
K
prev piece
k
next piece
j
cycle tier
t
this menu
?
sources3
expand
  1. 01
  2. 02
  3. 03

Trademarks belong to their respective owners. Editorial reference only.