Linux Flags 101 — What They Are and How They Work?

Have you ever run a command in Linux and seen things like -l, --help, or -avz? Those are flags — the magical switches that control the behavior of almost every command you run in your terminal.

But for beginners and even intermediate developers, flags can be confusing. Why are some short like -a, and others long like --all? Can you mix them? What does -xzvf even mean in tar?

In this blog we’ll break it all down — in the most structured way possible.

What are Flags in Linux?

Flags (also called options or switches) modify the default behavior of a command. You pass them after the command to ask it to do something extra or different.

Example:

ls         # Just lists files
ls -l      # Lists files in long format

Types of Flags in Linux

Linux flags come in various flavors. Let’s explore the most common ones with real examples:

1. Short Flags (-x)

These are the most basic. A short flag is usually a single letter preceded by a single dash -.

Example:

ls -a
  • -a shows all files, including hidden ones.

More Examples:

grep -i "hello" file.txt   # -i ignores case
rm -r folder/              # -r means recursive delete

They’re short, sweet, and often cryptic. You'll need to memorize or check --help.

2. Long Flags (--example)

These are more descriptive. Long flags start with two dashes -- and are easier to understand.

Example:

ls --all

Equivalent to ls -a, but now it’s clearer.

Other Examples:

docker build --tag myapp .
git commit --message "Initial commit"

✅ Use long flags when scripting or sharing commands with teammates — they’re easier to read.

3. Combined Short Flags (-xyz)

You can combine multiple short flags into a single flag block — if the command supports it.

Example:

tar -xzvf file.tar.gz

This is the same as:

tar -x -z -v -f file.tar.gz
  • -x: extract

  • -z: filter with gzip

  • -v: verbose

  • -f: use archive file

It’s compact but looks intimidating. Break it down to learn what each part does.

4. Flags with Arguments

Some flags need a value or parameter.

Examples:

grep -e "pattern" file.txt      # -e is followed by the pattern
ls --color=auto                 # = assigns a value
--output=file.txt               # sends output to file.txt

Spacing Matters:

  • Some flags accept both --flag=value and --flag value formats

  • Some only accept one of the formats

👉 Always check with man <command> or <command> --help

Real-World Use Case: Copying Files Verbosely

Let’s say you want to copy files from one folder to another and see progress.

cp -v myfile.txt /backup/
  • -v = verbose. It shows what’s being copied.

Now, what if you want to copy entire folders?

cp -rv folder1/ folder2/
  • -r: recursive copy

  • -v: show progress

Real Use Case: Docker + Git

Let’s look at a common DevOps example.

docker build -t myimage:latest .
  • -t is short for --tag

  • It tags the Docker image with the name myimage:latest

Another example:

git log --oneline --graph --decorate
  • All are long flags. Together, they show a beautiful, summarized git commit history.

Summary

Flag TypeExampleDescription
Short Flag-aOne-letter options like ls -a
Long Flag--allMore readable form: ls --all
Combined Short Flags-xzvfCombine: tar -x -z -v -f
Flags with Arguments--output=result.txtAssign a value to a flag

🪪 Finally

Flags are the secret handshake to unlock powerful features in Linux commands. Once you start noticing them, you’ll feel more confident and in control.

Keep exploring — and don’t be afraid to break things (in a test environment 😉).


Written with ❤️ by Anuj Kumar Upadhyay

10
Subscribe to my newsletter

Read articles from Anuj Kumar Upadhyay directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

Anuj Kumar Upadhyay
Anuj Kumar Upadhyay

I am a developer from India. I am passionate to contribute to the tech community through my writing. Currently i am in my Graduation in Computer Application.