Linux Command Reference

By this point in the course you have met dozens of individual Linux commands, but a real terminal session bounces between file management, text processing, permissions, process control, and networking within the space of a few minutes. This lesson is a consolidated reference: categorized tables of the commands you have used (and a few closely related ones), plus a refresher on how to look up any command’s exact options yourself instead of memorizing everything. Treat it as a page to bookmark and return to, not a one-time read.

Overview: How Linux Finds and Runs a Command

When you type a command and press Enter, Bash does not immediately go searching the disk. It first checks whether the word matches a shell builtin (like cd, echo, export, or type itself) or a defined alias or function. Builtins exist because some operations, like changing the shell’s own working directory, can only be done by the shell process itself — a separate child process could not change its parent’s state, so cd has to be handled internally rather than as an external program.

If the word is not a builtin, alias, or function, Bash treats it as an external program and searches the directories listed in the PATH environment variable, in order, for an executable file with that name. Once found, Bash calls fork() to duplicate itself into a new child process, then that child calls exec() to replace its own program image with the target binary. The parent shell suspends and waits for the child to finish, then reads its exit status into the special variable $?. This fork-then-exec pattern is how every external command on Linux actually starts.

Manual pages (man) are organized into numbered sections, and the same word can appear in more than one: section 1 is user commands, section 2 is system calls, section 3 is C library functions, section 5 is file formats, and section 8 is administration commands. man printf and man 3 printf describe two different things with the same name — the shell command versus the C library function. When man alone does not answer your question, that is usually why.

Syntax: Anatomy of a Command Line

Nearly every command you will meet follows the same shape:

command [options] [arguments]

An option (or flag) changes how the command behaves; an argument is what the command acts on, such as a file or directory. Short options are a single dash plus one letter and can usually be combined (ls -la means ls -l -a); long options are a double dash plus a full word (ls --all) and are easier to read in scripts. Some options take a value of their own, either as a separate word (-o value) or joined with = (--output=value).

Commands are also combined with control operators:

Symbol Meaning
; Run the next command regardless of the previous one’s result
&& Run the next command only if the previous one succeeded (exit status 0)
|| Run the next command only if the previous one failed
| Pipe: connect one command’s stdout to the next command’s stdin
> / >> Redirect stdout, overwriting or appending to a file
& Run the preceding command in the background

Command Categories at a Glance

File and Directory Management

Command Purpose
ls List directory contents
cd Change the current directory
pwd Print the current working directory
mkdir Create a directory
rm Remove files or directories (-r for recursive)
cp Copy files or directories
mv Move or rename files or directories
find Search a directory tree by name, type, size, or age
ln Create hard or symbolic (-s) links

Viewing and Processing Text

Command Purpose
cat Print a file’s contents to the terminal
less Page through a file’s contents interactively
head / tail Show the first / last lines of a file (tail -f follows a growing log)
grep Search text for lines matching a pattern
sed Stream editor for find-and-replace and text transformations
awk Pattern-driven text processing by field and record
sort / uniq Sort lines and collapse or count duplicates
wc Count lines, words, and bytes

Permissions and Ownership

Command Purpose
chmod Change read/write/execute permissions, e.g. chmod 755 file
chown Change a file’s owning user (and optionally group)
chgrp Change a file’s owning group
umask Show or set the default permission mask for new files

Process and Job Control

Command Purpose
ps Snapshot of running processes
top Live, updating view of processes and resource usage
kill Send a signal to a process by PID (SIGTERM by default, -9 for SIGKILL)
jobs, bg, fg List, resume in background, or bring a job to the foreground
nice Start a process with an adjusted scheduling priority

Networking and Remote Access

Command Purpose
ip a Show network interfaces and their IP addresses
hostname -I Print the machine’s IP address(es)
ping Test reachability of a host
ss Show open sockets and listening ports
ssh Open a secure remote shell on another machine
scp Copy files to or from a remote machine over SSH
curl / wget Fetch data from a URL, or download a file

Archives and Compression

Command Purpose
tar Bundle files into an archive (-c create, -x extract, -f filename)
gzip / gunzip Compress or decompress a single file
zip / unzip Create or extract a .zip archive

Package Management

Command Purpose
apt update Refresh the package index (Debian/Ubuntu)
apt install Install a package (Debian/Ubuntu)
dnf install Install a package (RHEL/Fedora equivalent)
dpkg -l List installed packages (Debian/Ubuntu)

Disk and System Info

Command Purpose
df -h Show disk space usage per filesystem, human-readable
du -sh Show the total size of a directory
free -h Show memory and swap usage
uname -r Show the running kernel version
uptime Show how long the system has been running and its load

Examples

Example 1: Looking Up a Command You Half-Remember

Instead of guessing a flag, ask the command itself. Most GNU tools print a short summary with --help:

ls --help

Output:

Usage: ls [OPTION]... [FILE]...
List information about the FILEs (the current directory by default).
Sort entries alphabetically if none of -cftuvSUX nor --sort is specified.

  -a, --all                  do not ignore entries starting with .
  -l                         use a long listing format
  -h, --human-readable       with -l and -s, print sizes like 1K 234M 2G
      --help     display this help and exit
      --version  output version information and exit

man ls opens the same command’s full manual page in a pager (press q to quit) with far more detail than --help. When you don’t even remember the command’s name, search by keyword instead:

apropos "disk usage"

Output:

df (1)                - report file system disk space usage
du (1)                - estimate file space usage

apropos (equivalent to man -k) searches the short description line of every installed man page, which makes it the fastest way to go from "I know what I want to do" to "here is the command name."

Example 2: A System and Network Snapshot Script

A short script can combine several reference commands into one useful report:

#!/usr/bin/env bash
set -euo pipefail

echo "Hostname: $(hostname)"
echo "Kernel:   $(uname -r)"
echo "Uptime:   $(uptime -p)"
echo "IP addr:  $(hostname -I | awk '{print $1}')"
echo "Disk (/): $(df -h / | awk 'NR==2 {print $4 " free of " $2}')"
echo "Memory:   $(free -h | awk '/^Mem:/ {print $3 " used of " $2}')"

Save this as system-snapshot.sh, make it executable, and run it:

chmod +x system-snapshot.sh
./system-snapshot.sh

Output:

Hostname: web01
Kernel:   6.8.0-51-generic
Uptime:   up 3 days, 4 hours, 12 minutes
IP addr:  10.0.2.15
Disk (/): 18G free of 40G
Memory:   2.1G used of 3.9G

Each $(...) is command substitution: Bash runs the command inside it in a subshell, captures whatever it writes to stdout, strips the trailing newline, and drops the result in place as text. That’s why awk can be layered on the end of each pipeline to pull out just the field we want.

Example 3: Seeing What a Command Really Is

The same word can be a builtin, an alias, a function, or a binary on disk — and that affects how it behaves. type tells you which:

type ls
type cd
which python3
echo "$PATH"

Output:

ls is aliased to `ls --color=auto'
cd is a shell builtin
/usr/bin/python3
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin

This explains why ls shows color even though you never typed a flag for it (an alias is quietly adding --color=auto), and why cd has no location on disk at all — it lives inside Bash itself. which only reports external binaries found on PATH, so it correctly stays silent about builtins and aliases.

How It Works Step by Step

  • You run ./system-snapshot.sh. Because it starts with ./, Bash skips the PATH search and executes that exact file in the current directory.
  • The kernel reads the first line, #!/usr/bin/env bash, sees the #! shebang, and hands the rest of the file to /usr/bin/env, which locates bash on PATH and runs the script through it.
  • set -euo pipefail takes effect first: -e exits immediately if any command fails, -u treats an unset variable as an error, and -o pipefail makes a pipeline fail if any stage of it fails, not just the last one.
  • Each echo line runs its embedded $(...) command substitution in a child subshell, waits for it to exit, captures its stdout, and substitutes the text before echo ever runs.
  • When you instead type a bare command name like which python3, Bash walks each directory in $PATH left to right, stops at the first python3 executable it finds, and prints that path without running it.

Common Mistakes

Mistake 1: Looping Over ls Output

Parsing ls in a loop breaks on filenames containing spaces or newlines, and needlessly forks an extra process:

for f in $(ls *.log); do
  rm $f
done

The unquoted $(ls *.log) is word-split on whitespace, so a file named access august.log becomes two separate words, and the unquoted $f in rm $f compounds the problem. Let Bash’s own globbing hand you the filenames directly instead:

for f in *.log; do
  rm -- "$f"
done

The pattern *.log expands safely with no subshell and no word-splitting, quoting "$f" keeps each filename intact, and -- stops rm from misreading a filename that happens to start with a dash as an option.

Mistake 2: Forgetting chmod +x Before Running a Script

A freshly written or downloaded script has no execute permission by default:

./system-snapshot.sh

Output:

bash: ./system-snapshot.sh: Permission denied

Read and write permission is not enough to run a file directly — the execute bit must be set for your user (or group/other, depending who is running it). Fix it once, then run it:

chmod +x system-snapshot.sh
./system-snapshot.sh

Best Practices

  • Check --help or man <command> before guessing a flag — a wrong guess that happens to be syntactically valid can silently do the wrong thing.
  • Use apropos (man -k) to find a command by what it does when you don’t know its name.
  • Use type to find out whether a command is a builtin, alias, function, or binary before you rely on its exact behavior.
  • Prefer long-form flags (--verbose, --all) in scripts for readability; short flags (-v, -a) are fine for quick interactive use.
  • Keep your own short cheat sheet of the ten or so commands and flags you personally use most — it will be faster than searching every time.
  • Use Ctrl+R to reverse-search your shell history instead of retyping a long command you know you’ve run before.
  • Always quote variable and command-substitution expansions ("$var", "$(cmd)") in scripts to avoid word-splitting surprises.

Practice Exercises

  • You want to check how much free memory the system has but can’t remember the command. Use apropos or man -k with a relevant keyword to find it, then run it.
  • Run type on ls, grep, cd, and echo on your own machine and note which are builtins, which are aliases, and which are external binaries. Then run which on each and explain any that print nothing.
  • Write a five-line system-snapshot.sh script (or extend the one from this lesson) that also reports the number of currently running processes using ps. Make it executable and run it.

Summary

  • Bash resolves a typed word as a builtin/alias/function first, then searches $PATH for an external binary, then runs it via fork() and exec().
  • man, --help, apropos, and type together let you look up or verify any command instead of memorizing every flag.
  • Man pages are split into numbered sections, so the same name (like printf) can mean different things in different sections.
  • The command tables in this lesson group the essentials by task: files, text, permissions, processes, networking, archives, packages, and system info.
  • Always quote expansions, prefer globs over parsing ls, and remember a new script needs chmod +x before it can run directly.