Linux Commands Cheat Sheet

161+ commands worth keeping within reach, grouped by what you're trying to do. Every entry links to its full guide — syntax, options, real examples and an interactive terminal. Print this page for the wall, or work through the 48-lesson course to put it in your fingers.

161 commands 15 sections 137 linked guides Click any command to copy it

Files & directories

Create, copy, move, destroy. No trash bin — read twice before Enter.

11
  • Create a directory guide ›
  • Create a nested path in one go (no error if it exists) guide ›
  • Create an empty file / refresh its timestamp guide ›
  • Copy a file guide ›
  • Copy a tree preserving permissions, times, symlinks guide ›
  • Instant backup: expands to cp file file.bak guide ›
  • Move or rename (same operation) guide ›
  • Delete a file — permanently guide ›
  • Delete a directory and everything inside guide ›
  • Create a symbolic link guide ›
  • Update an existing symlink to a directory guide ›

Viewing files

Read without opening an editor.

10
  • Print the whole file guide ›
  • Print with line numbers guide ›
  • Page through: / search, G end, q quit guide ›
  • Follow a growing file, Ctrl+C to browse guide ›
  • First 20 lines guide ›
  • Last 20 lines guide ›
  • Follow live, surviving log rotation guide ›
  • Everything except the first line (skip a CSV header) guide ›
  • Count lines
  • Show what changed between two files guide ›

Pipes & redirection

The idea that makes the shell powerful.

11
  • Write output to a file (replaces contents)
  • Append output to a file
  • Redirect only errors
  • Redirect output AND errors to one file
  • Discard error messages
  • Pipe: output of cmd1 becomes input of cmd2
  • See it live and save a copy guide ›
  • The correct way to append to a root-owned file guide ›
  • Run cmd2 only if cmd1 succeeded
  • Run cmd2 only if cmd1 failed
  • Compare the output of two commands guide ›

Text processing

The filters that live in the middle of pipelines.

15
  • Print the second column of any output guide ›
  • Third column of a comma-separated file guide ›
  • Sum a column guide ›
  • Deduplicate, preserving original order guide ›
  • Replace every occurrence (prints the result) guide ›
  • Replace in place, keeping a .bak backup guide ›
  • Print only lines 20 to 40 guide ›
  • Strip comment lines guide ›
  • Extract columns 1 and 3 guide ›
  • Sort lines alphabetically
  • Sort numerically, descending
  • Count occurrences of each line guide ›
  • Show only the duplicated lines guide ›
  • Uppercase everything guide ›
  • Strip Windows carriage returns guide ›

Permissions & ownership

r=4, w=2, x=1 — owner, group, others.

9
  • Make a file executable guide ›
  • rwxr-xr-x — directories and executables guide ›
  • rw-r--r-- — regular files guide ›
  • rw------- — private keys and secrets guide ›
  • Correct recursive fix for directories guide ›
  • Correct recursive fix for files guide ›
  • Change owner and group of a tree guide ›
  • Copy ownership from another file guide ›
  • Show which permission bits are removed from new files

Processes

What is running, and how to stop it politely.

12
  • Every running process guide ›
  • Top memory consumers guide ›
  • Find PIDs by command line guide ›
  • Live monitor (htop is friendlier) guide ›
  • Ask a process to close cleanly guide ›
  • Force termination — last resort, nothing is saved guide ›
  • Signal processes matching a pattern guide ›
  • Tell a daemon to reload its configuration guide ›
  • Run in the background guide ›
  • List, foreground, resume background jobs guide ›
  • Keep running after you log out guide ›
  • Suspend the current foreground job guide ›

Disk & memory

Where the space and the RAM went.

7
  • Free space per filesystem guide ›
  • Inode usage (full disk with free bytes?) guide ›
  • Total size of a directory guide ›
  • The disk-hunt drill-down guide ›
  • Memory — read "available", not "free" guide ›
  • Block devices and where they are mounted
  • What is mounted where

Networking

Reachability, addresses, ports, names.

13
  • Is it reachable, and how far guide ›
  • Your addresses, one line per interface guide ›
  • Routing table and default gateway guide ›
  • Which interface and source IP would be used guide ›
  • Listening ports with the owning process guide ›
  • Current established connections guide ›
  • Resolve a name guide ›
  • Ask a specific resolver (bypass your cache) guide ›
  • Where the domain's mail goes guide ›
  • Response headers only guide ›
  • Just the status code guide ›
  • Send JSON to an API guide ›
  • Download, resuming if interrupted guide ›

Remote & transfer

Working on machines that are not yours.

9
  • Open a remote shell guide ›
  • Custom port guide ›
  • Run one command remotely and return guide ›
  • Create a key pair (once per machine) guide ›
  • Install your key — no more passwords guide ›
  • Tunnel a remote port to your machine guide ›
  • Copy one file over SSH guide ›
  • Sync a tree — only what changed travels guide ›
  • Dry run of a mirror (always do this first) guide ›

Archives & compression

Packing, shipping, unpacking.

9
  • Create a compressed archive guide ›
  • Extract it (the one to memorize) guide ›
  • List contents without extracting guide ›
  • Extract somewhere specific guide ›
  • Compress, keeping the original guide ›
  • Search inside a compressed file guide ›
  • Windows-friendly archive guide ›
  • Inspect before extracting guide ›
  • Fingerprint — verify a download guide ›

System & services

systemd, packages, scheduled jobs.

12
  • State, PID and recent logs guide ›
  • Restart a service guide ›
  • Start now and at every boot guide ›
  • Anything broken on this machine? guide ›
  • Follow one service's logs live guide ›
  • Everything the system did in a time window guide ›
  • Errors since boot, all sources guide ›
  • Refresh the catalog, then patch guide ›
  • Install with dependencies guide ›
  • Edit / list scheduled jobs guide ›
  • Cron line: every day at 03:00 guide ›
  • Load, kernel version, CPU count

Shell & environment

Your setup, your shortcuts, your history.

11
  • Where the shell looks for commands guide ›
  • Set a variable children will inherit guide ›
  • Set it for one command only guide ›
  • Reload your config in this shell guide ›
  • Create a shortcut (put it in ~/.bashrc) guide ›
  • Is it an alias, function, builtin or file? guide ›
  • Which file would actually run guide ›
  • Portable existence check for scripts guide ›
  • Search your past commands guide ›
  • Repeat the last command with sudo guide ›
  • The last argument of the previous command guide ›

Keyboard shortcuts

The fastest wins on this page. Tab and Ctrl+R alone save more typing than every alias you'll ever write.

10
  • Tab Complete a file or command name — nobody types full paths
  • Ctrl+R Search your command history as you type (then Enter to run)
  • Ctrl+C Stop the running command
  • Ctrl+D End of input / log out of the shell
  • Ctrl+Z Suspend the current job (then fg or bg)
  • Ctrl+L Clear the screen (same as clear)
  • Ctrl+A orCtrl+E Jump to the beginning / end of the line
  • Ctrl+W orCtrl+U Delete the previous word / the whole line
  • Alt+. Insert the last argument of the previous command
  • Up orDown Walk through previous commands
Want all of this — plus internals, worked examples and diagrams — as one printable book? See The Linux Command Line Handbook.