Linux commands cheat sheet
The 40 Linux commands you will use most, grouped by job, each with an example you can copy. Each row links to a lesson where you run it in a practice terminal and your result is checked.
The examples use the GNU tools found on Ubuntu, Debian and most Linux systems. File names like notes.txt and logs/app.log stand for your own files.
Files and directories
| Name | What it does | Example | Practice |
|---|---|---|---|
| pwd | Prints the directory you are in. | | Paths and the working directory |
| ls -la | Lists files with permissions, owner, size and date, hidden files included. | | Long listings and hidden files |
| cd | Changes directory. cd .. goes up one level and cd ~ goes to your home directory. | | Paths and the working directory |
| mkdir -p | Creates a directory; -p also creates any missing parent directories. | | Nested directory trees |
| cp -r | Copies files; -r copies a directory and everything in it. | | Recursive copies and backups |
| mv | Moves a file or renames it. | | File moves and precise renames |
| rm -r | Deletes files; -r deletes a directory and its contents. There is no recycle bin. | | Safe recursive removal |
| find | Searches a directory tree for files by name, type, size or age. | | File tests and execution actions |
Read files
| Name | What it does | Example | Practice |
|---|---|---|---|
| cat | Prints a whole file. | | Files, pagers and line windows |
| less | Opens a long file one screen at a time. Type /word to search and q to quit. | | Files, pagers and line windows |
| head, tail | The first lines of a file; tail -n gives the last ones. | | Files, pagers and line windows |
| tail -f | Shows the end of a file and keeps printing new lines as they are written. Ctrl+C stops it. | | Log tails and recovery evidence |
| wc -l | Counts lines (-l), words (-w) or bytes (-c). | | Pipelines, exclusions and counts |
Search and edit text
| Name | What it does | Example | Practice |
|---|---|---|---|
| grep | Prints the lines that match a pattern; -i ignores case and -v shows the lines that do not match. | | Extended regular expressions |
| grep -rn | Searches every file under a directory and shows the file name and line number of each match. | | Recursive searches with source lines |
| sed | Finds and replaces text as it streams through. The file is not changed unless you add -i. | | Text replacement without source edits |
| awk | Works field by field: filter rows, print columns or add them up. -F sets the separator. | | Field filters and conditional sums |
| cut | Takes fields out of each line; -d sets the separator and -f picks the fields. | | Field extraction and case conversion |
| tr | Swaps or deletes characters, such as lower case to upper case. | | Field extraction and case conversion |
| sort | uniq -c | sort orders lines, then uniq -c counts each run of equal lines. | | Sorting and duplicate groups |
Pipes and redirection
| Name | What it does | Example | Practice |
|---|---|---|---|
| | (pipe) | Sends one command's output into the next command. | | Pipelines, exclusions and counts |
| > and >> | > writes output to a file and replaces what was there; >> adds it to the end. | | Input, overwrite and append |
| xargs | Turns lines of input into arguments for another command. | | Streams as command arguments |
| && and || | && runs the next command only if the first one succeeded; || runs it only if the first one failed. | | Exit codes and conditional lists |
Permissions
| Name | What it does | Example | Practice |
|---|---|---|---|
| chmod | Sets permissions. 755 lets the owner read, write and run the file, and everyone else read and run it. | | Octal and symbolic modes |
| chown | Changes a file's owner and group. It usually needs sudo. | | Owners and administrative changes |
| sudo | Runs one command as the administrator (root) after asking for your password. | | Owners and administrative changes |
Variables and scripts
| Name | What it does | Example | Practice |
|---|---|---|---|
| export | Sets a variable that programs started from this shell can read. | | Variables and exported settings |
| which | Shows which file runs when you type a command, found through the directories in $PATH. | | Executable discovery through PATH |
| $1 (arguments) | Runs a script with an argument; inside the script, $1 is the first argument and $# counts them. | | Scripts and positional arguments |
| if [ -f ] | Runs commands only when a test passes, such as a file existing (-f) or a directory existing (-d). | | File tests and if branches |
| for | Repeats commands for each item in a list, here each CSV file. | | For loops and while boundaries |
Processes
| Name | What it does | Example | Practice |
|---|---|---|---|
| ps aux | Lists running processes with their process ID (PID), owner, CPU and memory. | | Process snapshots and signals |
| kill | Asks a process to stop, by its PID. kill -9 forces it when it does not respond. | | Process snapshots and signals |
| top | A live view of the processes using the most CPU and memory. q quits. | | Process snapshots and signals |
| & and jobs | & starts a command in the background; jobs lists what is running there. | | Background jobs and process IDs |
Network and archives
| Name | What it does | Example | Practice |
|---|---|---|---|
| curl -I | Requests a URL; -I shows only the response headers, such as the status code. | | HTTP checks and shell failures |
| ssh | Opens a shell on another machine over an encrypted connection. | | Remote shell context |
| tar -czf | Packs a directory into a compressed .tar.gz file. | | Compressed archives and restoration |
| tar -xzf | Unpacks a .tar.gz file into the current directory. | | Compressed archives and restoration |
Checked against
Every row was last checked on Nov 20, 2026.
Questions
Do these commands work on Ubuntu, Debian and macOS?
Yes for Ubuntu, Debian, Fedora and other Linux systems, which use the GNU versions of these commands. macOS uses BSD versions: the common options here work, but a few, such as sed -i, behave differently.
Can I practice the commands without installing Linux?
Yes. The Linux playground and the Linux course run a terminal in your browser with sample files, so you can try every command here safely.
Can I print this Linux cheat sheet?
Yes. Press Print or save as PDF; the printed layout keeps the commands and examples and leaves out the rest of the page.