Bash (Debian / Linux) Cheat Sheet
The standard Linux shell. Use man command or command --help for details on any command.
On this page
Navigation #
| Command | Action |
|---|---|
| Print the current folder | |
| List files and folders ( = all files, details, readable sizes) | |
| / / / | Go to a path / up / home / previous folder |
| Folder tree, 2 levels deep | |
or Ctrl + L | Clear the screen |
Files & Folders #
| Command | Action |
|---|---|
| Create an empty file / update its timestamp | |
| Create nested folders | |
| / | Copy a file / folder |
| Move or rename | |
| / | Delete a file / folder |
| Force-delete, no questions (double-check the path!) | |
| Create a symbolic link | |
| Print a file | |
Scroll a file (q to quit, / to search) | |
| / | First / last 20 lines |
| Follow a log live | |
| Count lines | |
| Size of a folder | |
| Detect the file type |
Search #
| Command | Action |
|---|---|
| Find files by name | |
| Files bigger than 100 MB | |
| Files changed in the last 24 h | |
| Search in a file | |
| Recursive, case-insensitive, with line numbers | |
| Lines that do not match | |
| / | Where a command comes from |
| Fast search via a database ( first) |
Permissions & Ownership #
| Command | Action |
|---|---|
| Make executable | |
| rw-r--r-- (normal file) | |
| rwxr-xr-x (folder / script) | |
| Recursively give the owner read/write | |
| Change the owner | |
sudo cmd | Run as root |
| Root shell |
Numbers: r=4 w=2 x=1 → add them per owner / group / others.
Processes #
| Command | Action |
|---|---|
| All processes | |
| Find a process | |
| / | Live process monitor |
kill PID / | Stop / force-kill |
| Kill by name | |
cmd & | Run in the background |
| / / | List jobs / bring to front / continue in background |
Ctrl + Z | Pause the current program |
| Keep running after logout |
System & Services #
| Command | Action |
|---|---|
| Kernel info | |
| Distro and version | |
| How long it has been running + load | |
| Memory usage | |
| Disk space | |
| Disks and partitions | |
| Service status | |
| Restart a service | |
| Start now and at boot | |
| Follow a service's logs | |
| / | Reboot / power off |
Users #
| Command | Action |
|---|---|
| / | Current user / user and group IDs |
| Create a user (Debian) | |
| Give admin rights | |
| Change your password | |
| Switch user |
Network #
| Command | Action |
|---|---|
| IP addresses | |
| Routes / default gateway | |
| Ping 4 times | |
| Response headers only | |
| / | Download a file |
| Listening ports and their programs | |
| / | DNS lookup |
| Local IPs |
Archives #
| Command | Action |
|---|---|
| Create a .tar.gz | |
| Extract a .tar.gz | |
| Extract to a folder | |
| / | Zip / unzip |
Redirection & Chaining #
| Syntax | Meaning |
|---|---|
cmd > file / cmd >> file | Write / append output |
cmd 2> err.log | Write errors |
cmd &> all.log | Output and errors |
cmd > /dev/null 2>&1 | Discard everything |
a | b | Pipe |
a && b / a || b | Run b if a succeeds / fails |
cmd | tee file | Show on screen and write to a file |
$(cmd) | Use a command's output inside another command |
Keyboard & History #
| Key | Action |
|---|---|
Tab (twice) | Autocomplete / show options |
Ctrl + R | Search history |
Ctrl + A / Ctrl + E | Start / end of line |
Alt + B / Alt + F | Word back / forward |
Ctrl + U / Ctrl + K | Cut before / after the cursor |
Ctrl + W | Cut the previous word |
Ctrl + Y | Paste what you cut |
Ctrl + C | Stop the command |
Ctrl + D | Exit the shell (end of input) |
!! | Repeat the last command (sudo !! = again as root) |
!$ | Last argument of the previous command |
| Show history |
Variables & Scripts #
#!/usr/bin/env bash
set -euo pipefail # stop on errors, unset variables and pipe failures
name="Milan" # no spaces around =
echo "Hello $name"
export API_KEY="abc" # make it visible to child programs
for f in *.txt; do
echo "Processing $f"
done
if [ -f config.json ]; then
echo "exists"
fi
Run it with chmod +x script.sh && ./script.sh. Aliases go in ~/.bashrc, and source ~/.bashrc reloads it.
pwdPrint the current folder. pwd [-L | -P]
| Option | What it does |
|---|---|
-L | Logical path, keeps symbolic links (default) |
-P | Physical path, symbolic links resolved |
Git Bash tip: pwd -W prints the Windows-style path (C:/Users/…).
lsList the files and folders in a directory. ls [options] [path…]
| Option | What it does |
|---|---|
-l | Long list: permissions, owner, size, date |
-a, --all | Also show hidden files (names starting with .) |
-A, --almost-all | Hidden files too, but without . and .. |
-h, --human-readable | Sizes like 4.0K, 12M, 1.1G (use with -l) |
-t | Sort by modification time, newest first |
-S | Sort by size, largest first |
-X | Sort by file extension |
-v | Natural sort of numbers (file2 before file10) |
-r, --reverse | Reverse the sort order |
-R, --recursive | List all subfolders too |
-d | List the folder itself, not what's inside (ls -d */ = only folders) |
-1 | One name per line |
-F, --classify | Add / after folders, * after executables, @ after links |
-i | Show inode numbers |
-n | Numeric user and group IDs |
-s | Show the allocated size of each file |
--color=auto | Colour output (always / never) |
--group-directories-first | Folders before files |
--time-style=long-iso | Dates as 2026-10-01 14:05 |
--sort=WORD | Sort by size, time, extension, version or none |
Popular combinations: ls -la (everything, detailed) · ls -lah (+ readable sizes) · ls -lt (newest first) · ls -lS (biggest first).
macOS: -G enables colour; the long --options don't exist there. Full list: man ls or ls --help.
cdChange the current folder. cd [path]
| Usage | What it does |
|---|---|
cd folder | Go into a folder (relative to where you are) |
cd /var/log | Go to an absolute path |
cd .. | One folder up (cd ../.. = two up) |
cd or cd ~ | Your home folder |
cd - | Back to the previous folder |
cd / | The root of the filesystem |
cd "My Folder" | Paths with spaces need quotes (or My\ Folder) |
-P | Resolve symbolic links to the real path |
-L | Follow symbolic links as they are (default) |
Git Bash: drives are /c/, /d/… WSL: Windows drives are under /mnt/c/.
treeShow a folder as a tree. tree [options] [folder] (install: sudo apt install tree)
| Option | What it does |
|---|---|
-L N | Only N levels deep |
-a | Include hidden files |
-d | Folders only |
-f | Show the full path of every item |
-h | Show sizes (readable) |
-I "pattern" | Ignore matching names: -I "node_modules|dist" |
-P "pattern" | Only show files matching: -P "*.md" |
--gitignore | Skip what .gitignore ignores |
--dirsfirst | Folders before files |
-C / -n | Colours on / off |
-J | Output as JSON |
-o file | Write the tree to a file |
--noreport | Hide the "N directories, M files" summary |
clearClear the terminal screen. Shortcut: Ctrl + L.
| Option | What it does |
|---|---|
-x | Don't clear the scrollback (only the visible screen) |
reset | (separate command) fully reset a garbled terminal |
touchCreate an empty file, or update a file's timestamp. touch [options] file…
| Option | What it does |
|---|---|
touch a.txt b.txt | Create several files at once |
touch file{1..5}.txt | Create file1.txt … file5.txt (brace expansion) |
-c, --no-create | Don't create the file if it doesn't exist |
-a | Change only the access time |
-m | Change only the modification time |
-d "2026-01-01 12:00" | Set a specific date/time |
-t 202601011200 | Set the time as [[CC]YY]MMDDhhmm[.ss] |
-r other.txt | Copy the timestamp from another file |
mkdirCreate folders. mkdir [options] folder…
| Option | What it does |
|---|---|
-p, --parents | Create parent folders as needed; no error if it exists |
-v, --verbose | Print every folder created |
-m 755 | Set permissions while creating |
mkdir -p src/{components,pages,utils} | Several subfolders in one go |
cpCopy files and folders. cp [options] source… destination
| Option | What it does |
|---|---|
-r, -R | Copy folders with everything inside |
-a, --archive | Recursive + keep permissions, owners, timestamps, links (best for backups) |
-i | Ask before overwriting |
-n | Never overwrite existing files |
-f | Force: delete a destination file that can't be opened, then copy |
-u | Only copy when the source is newer |
-v | Show every file copied |
-p | Keep mode, owner and timestamps |
-l | Make hard links instead of copies |
-s | Make symbolic links instead of copies |
-L | Follow symbolic links (copy what they point to) |
-t folder | Destination folder first: cp -t backup/ *.txt |
--backup | Keep a backup (file~) of files that would be overwritten |
Watch out: cp -r src dst creates dst/src when dst already exists (even with src/; unlike rsync, a trailing slash doesn't change this).
mvMove or rename files and folders. mv [options] source… destination
| Option | What it does |
|---|---|
-i | Ask before overwriting |
-n | Never overwrite |
-f | Overwrite without asking (default) |
-u | Only move when the source is newer |
-v | Show what is moved |
-b | Back up files that would be overwritten |
-t folder | Destination first: mv -t archive/ *.log |
-T | Treat the destination as a file, never as a folder |
Renaming is just moving: mv old.txt new.txt.
rmDelete files and folders. There is no recycle bin. rm [options] file…
| Option | What it does |
|---|---|
-r, -R | Delete folders and everything in them |
-f | Force: no questions, no error if the file is missing |
-i | Ask before every file |
-I | Ask once (when deleting more than 3 files or recursively) |
-v | Show what is deleted |
-d | Delete empty folders |
--preserve-root | Refuse to delete / (on by default) |
--one-file-system | Don't cross into other mounted drives |
⚠ Double-check before rm -rf. Test the pattern first with ls: ls *.tmp → rm *.tmp.
lnCreate links. ln [options] target link-name
| Option | What it does |
|---|---|
-s | Symbolic (soft) link, the usual choice |
| (none) | Hard link (same file, two names; files only, same drive) |
-f | Replace an existing link |
-n | Treat a link to a folder as a normal file (use with -f to replace it) |
-r | Make the link path relative |
-v | Show what is created |
Example: ln -s ~/projects/app/config.json ./config.json
catPrint files (or join them). cat [options] file…
| Option | What it does |
|---|---|
-n | Number every line |
-b | Number non-empty lines only |
-s | Squeeze multiple empty lines into one |
-A | Show invisible characters: tabs as ^I, line ends as $ |
-E | Show $ at every line end (spot trailing spaces) |
-T | Show tabs as ^I |
cat a b > ab | Join files into a new one |
cat >> notes.txt | Type text and append it (end with Ctrl + D) |
lessScroll through a file or long output. less [options] file or command | less
| Option / key | What it does |
|---|---|
-N | Show line numbers |
-S | Don't wrap long lines (scroll sideways) |
-R | Show colours (git log | less -R) |
-i | Case-insensitive search |
+F | Follow the end of the file, like tail -f |
-X | Leave the content on screen after quitting |
Space / b | Page down / up |
g / G | Start / end of the file |
/text / ?text | Search forward / backward (n / N = next / previous) |
F | Start following (stop with Ctrl + C) |
q | Quit |
headShow the first lines of a file. head [options] file…
| Option | What it does |
|---|---|
-n 20 | First 20 lines (default 10) |
-n -5 | Everything except the last 5 lines |
-c 100 | First 100 bytes |
-q | Don't print file names when showing several files |
-v | Always print the file name |
tailShow the last lines of a file, or follow it live. tail [options] file…
| Option | What it does |
|---|---|
-n 50 | Last 50 lines (default 10) |
-n +100 | Everything from line 100 on |
-f | Follow: keep printing new lines (logs) |
-F | Follow and survive log rotation / file recreated |
-c 200 | Last 200 bytes |
--pid=1234 | Stop following when that process ends |
-s 5 | Check for new lines every 5 seconds (with -f) |
-q | No file-name headers |
Example: tail -f /var/log/syslog | grep error
wcCount lines, words and bytes. wc [options] file…
| Option | What it does |
|---|---|
-l | Lines |
-w | Words |
-c | Bytes |
-m | Characters (differs from bytes for UTF-8) |
-L | Length of the longest line |
Example: ls | wc -l counts the items in a folder.
duDisk usage of files and folders. du [options] [path…]
| Option | What it does |
|---|---|
-s | Only the total for each argument |
-h | Readable sizes |
-d 1, --max-depth=1 | Only N levels deep |
-a | Include files, not just folders |
-c | Add a grand total |
-x | Stay on one filesystem |
--exclude="*.log" | Skip matching files |
--apparent-size | Real file size instead of space used on disk |
Find what's big: du -h -d 1 | sort -h
fileDetect what kind of file something is (by content, not extension). file [options] file…
| Option | What it does |
|---|---|
-b | Brief: no file name in the output |
-i, --mime | MIME type: text/plain; charset=utf-8 |
-L | Follow symbolic links |
-z | Look inside compressed files |
-s | Read special files (disks, partitions) |
findSearch for files by name, type, size, date… find [path] [tests] [actions]
| Option | What it does |
|---|---|
-name "*.js" | Name matches (case-sensitive, quote the pattern) |
-iname "*.jpg" | Name matches, case-insensitive |
-type f / -type d / -type l | Files / folders / symbolic links |
-size +100M / -size -1024c | Bigger than 100 MB / smaller than 1 KB (-1k only finds empty files) |
-mtime -1 / -mtime +30 | Changed in the last day / more than 30 days ago |
-mmin -15 | Changed in the last 15 minutes |
-newer ref.txt | Changed after ref.txt |
-maxdepth 2 / -mindepth 1 | Limit how deep to search |
-path "*/src/*" | Match on the whole path |
-empty | Empty files or folders |
-user milan / -perm 644 | Owned by / with these permissions |
-not -name …, ! | Negate a test |
-o | OR between tests: \( -name "*.jpg" -o -name "*.png" \) |
-exec cmd {} \; | Run a command for every match |
-exec cmd {} + | Run the command once with all matches (faster) |
-delete | Delete the matches (put it last!) |
-print0 | Null-separated output for xargs -0 |
-ls | ls -l style output |
Example: find . -name "node_modules" -type d -prune -o -name "*.ts" -print
grepSearch for text in files or command output. grep [options] pattern [file…]
| Option | What it does |
|---|---|
-i | Ignore upper/lower case |
-r | Search all files in folders (recursive) |
-R | Recursive and follow symbolic links |
-n | Show line numbers |
-v | Show lines that do not match |
-w | Match whole words only |
-x | Match whole lines only |
-c | Count matching lines per file |
-l | Only list the names of matching files |
-L | Only list files without a match |
-o | Print only the matching part |
-E | Extended regex (+, ?, |, () without backslashes) |
-F | Plain text, no regex (fast, safe for special characters) |
-P | Perl regex (\d, lookarounds) |
-A 3 / -B 3 / -C 3 | 3 lines After / Before / around each match |
-e pattern | Several patterns: -e foo -e bar |
--include="*.js" | Only search matching files (with -r) |
--exclude-dir=node_modules | Skip folders (with -r) |
-h / -H | Hide / show file names |
-q | Quiet: only the exit code (for scripts) |
-s | Hide "permission denied" style errors |
--color=auto | Highlight matches |
Example: grep -rni --include="*.ts" "todo" src/
whichalso: typeShow where a command comes from. which [-a] command
| Option | What it does |
|---|---|
which node | Path of the program that runs |
-a | All matches in PATH, not just the first |
type ll | (Bash built-in) also shows aliases, functions and built-ins |
type -a python | Every definition of the name |
command -v git | Portable way, handy in scripts |
locatealso: plocate updatedbFind files fast from a prebuilt database. locate [options] pattern (install plocate or mlocate)
| Option | What it does |
|---|---|
-i | Ignore case |
-c | Only count matches |
-l 20 | Show at most 20 results |
-b | Match the file name only (not the whole path) |
-r | Use a regular expression |
-e | Only files that still exist |
sudo updatedb | Refresh the database (new files show up after this) |
chmodChange file permissions. chmod [options] mode file…
| Mode / option | What it does |
|---|---|
+x / -x | Add / remove execute for everyone |
u+x | Owner (user) may execute |
g+w, o-r | group may write, others may not read |
a=r | Everyone (all) read-only |
u=rwx,go=rx | Set exact permissions per class |
755 | rwxr-xr-x: folders, scripts |
644 | rw-r--r--: normal files |
600 | rw-------: private files (SSH keys) |
700 | rwx------: private folders (~/.ssh) |
-R | Apply to a folder and everything in it |
-v / -c | Show every change / only real changes |
--reference=file | Copy permissions from another file |
Numbers: r=4 w=2 x=1, added up per owner / group / others.
chownChange file owner and group. chown [options] user[:group] file…
| Usage / option | What it does |
|---|---|
chown milan file | New owner |
chown milan:www-data file | New owner and group |
chown :www-data file | Only the group (same as chgrp) |
-R | Recursively for a folder |
-v / -c | Show every change / only real changes |
-h | Change a symbolic link itself, not its target |
--reference=file | Copy owner and group from another file |
sudoRun a command as root (administrator). sudo [options] command
| Option | What it does |
|---|---|
sudo command | Run one command as root (asks your password) |
-i | Root login shell (exit to leave) |
-s | Root shell (non-login, stays in your current folder) |
-u user | Run as another user: sudo -u postgres psql |
-E | Keep your environment variables |
-l | List what you are allowed to run |
-v | Refresh the password timeout |
-k | Forget the password now (ask again next time) |
-e file | Edit a file as root safely (sudoedit) |
sudo !! | Run the previous command again as root |
psShow running processes. ps [options]
| Option | What it does |
|---|---|
aux | All processes of all users, with CPU / memory (BSD style) |
-ef | All processes, full format (System V style) |
-u milan | Processes of one user |
-p 1234 | One process by PID |
-C nginx | Processes by command name |
--sort=-%mem | Sort by memory, biggest first (-%cpu for CPU) |
-o pid,user,%cpu,%mem,cmd | Choose the columns |
f, --forest | Show parent/child tree |
-L | Show threads |
Example: ps aux --sort=-%mem | head
topalso: htopLive view of processes and resource use. top [options]
| Option / key | What it does |
|---|---|
-u milan | Only one user's processes |
-p 1234 | Watch specific PIDs |
-d 2 | Refresh every 2 seconds |
-n 1 -b | One snapshot in batch mode (for scripts / logs) |
-o %MEM | Sort by a field |
P / M / T | Sort by CPU / memory / time |
k | Kill a process (asks for the PID) |
1 | Show every CPU core |
c | Show full command lines |
h | Help · q quit |
htop (install it) is friendlier: mouse support, F3 search, F4 filter, F9 kill, F6 sort.
killSend a signal to a process (usually to stop it). kill [-signal] PID…
| Option | What it does |
|---|---|
kill 1234 | Ask nicely to stop (TERM, signal 15) |
-9, -KILL | Force kill immediately (can't be ignored) |
-15, -TERM | Normal stop (default) |
-1, -HUP | "Hang up": many services reload their config |
-2, -INT | Same as Ctrl + C |
-STOP / -CONT | Pause / resume |
-l | List all signal names |
kill %1 | Kill job 1 of this shell (see jobs) |
pkillalso: pgrepFind or kill processes by name. pkill [options] pattern
| Option | What it does |
|---|---|
pkill node | Stop every process named like "node" |
-f | Match the full command line: pkill -f "npm run dev" |
-x | Exact name match |
-u milan | Only processes of that user |
-9 | Force kill |
-n / -o | Only the newest / oldest match |
pgrep -a node | List matching PIDs with their command (no killing) |
pgrep -l node | PIDs with names |
jobsalso: fg bgManage background jobs in this shell.
| Usage | What it does |
|---|---|
command & | Start a command in the background |
Ctrl + Z | Pause the running foreground program |
jobs | List jobs (-l with PIDs, -p PIDs only) |
fg / fg %2 | Bring the last / job 2 back to the foreground |
bg / bg %2 | Continue a paused job in the background |
disown %1 | Detach a job so it survives closing the terminal |
wait | Wait until all background jobs are finished |
nohupKeep a command running after you log out. nohup command [args] &
| Usage | What it does |
|---|---|
nohup ./script.sh & | Run in the background; output goes to nohup.out |
nohup cmd > app.log 2>&1 & | Choose the log file, include errors |
nohup cmd > /dev/null 2>&1 & | Discard all output |
For long-running servers, a systemd service or tmux session is usually nicer.
unameShow system and kernel information. uname [options]
| Option | What it does |
|---|---|
-a | Everything |
-s | Kernel name (Linux) |
-r | Kernel release (6.8.0-45-generic) |
-v | Kernel version / build date |
-m | Hardware (x86_64, aarch64) |
-n | Host name |
-o | Operating system (GNU/Linux) |
uptimeHow long the system has been running, and the load. uptime [options]
| Option | What it does |
|---|---|
| (none) | Time, uptime, users, load average (1, 5, 15 min) |
-p | Pretty: up 3 days, 4 hours |
-s | Date and time the system started |
freeMemory (RAM) and swap usage. free [options]
| Option | What it does |
|---|---|
-h | Readable units |
-m / -g | In MB / GB |
-t | Add a total line |
-w | Wide: separate buffers and cache |
-s 2 | Repeat every 2 seconds |
Look at the available column, not "free": Linux uses spare RAM as cache.
dfFree space on drives. df [options] [path]
| Option | What it does |
|---|---|
-h | Readable sizes (powers of 1024) |
-H | Readable sizes (powers of 1000) |
-T | Show the filesystem type |
-i | Inodes instead of bytes |
-t ext4 / -x tmpfs | Only / exclude a filesystem type |
-l | Local filesystems only |
--total | Add a total line |
df -h . | Only the drive the current folder is on |
lsblkList disks and partitions. lsblk [options]
| Option | What it does |
|---|---|
-f | Show filesystems, labels, UUIDs and mount points |
-a | Include empty devices |
-d | Disks only, no partitions |
-p | Full device paths (/dev/sda1) |
-o NAME,SIZE,TYPE,MOUNTPOINT | Choose the columns |
-J | JSON output |
systemctlControl systemd services (background programs). systemctl [options] command [service]
| Command / option | What it does |
|---|---|
status nginx | Is it running? Recent log lines |
start / stop / restart | Start / stop / restart now |
reload | Reload the config without stopping |
enable / disable | Start / don't start at boot |
enable --now | Enable at boot and start right away |
is-active / is-enabled | Yes/no answer (for scripts) |
list-units --type=service | All loaded services |
--failed | Services that crashed |
daemon-reload | Re-read service files after editing them |
cat nginx / edit nginx | Show / override a service file |
mask / unmask | Block a service completely / undo |
--user | Manage your own user services |
--no-pager, -l | Plain output, full lines |
reboot / poweroff | Restart / shut down the machine |
journalctlRead the systemd logs. journalctl [options]
| Option | What it does |
|---|---|
-u nginx | Logs of one service |
-f | Follow live |
-n 100 | Last 100 lines |
-e | Jump to the end |
-r | Newest first |
-b / -b -1 | Since this boot / the previous boot |
-p err | Only errors and worse (warning, info…) |
--since "1 hour ago" | Time filter (--until too, or "2026-10-01 08:00") |
-k | Kernel messages (like dmesg) |
-o short-iso / -o json-pretty | Output format |
--no-pager | Plain output |
--disk-usage | Space the logs use |
--vacuum-time=2weeks | Delete older logs |
shutdownalso: reboot poweroffShut down or restart the computer (needs sudo).
| Usage | What it does |
|---|---|
shutdown now | Power off now (-h / -P mean the same) |
shutdown -r now | Restart now (same as reboot) |
shutdown +10 | Power off in 10 minutes |
shutdown 22:30 | Power off at a set time |
shutdown -r +5 "Updating" | Restart in 5 minutes with a message to logged-in users |
shutdown -c | Cancel a scheduled shutdown |
reboot / poweroff | Restart / power off immediately |
idalso: whoamiShow who you are and your groups.
| Usage | What it does |
|---|---|
whoami | Your user name |
id | User ID, group ID and all groups |
id -u / id -g | Only your user / group ID |
id -Gn | Names of all your groups |
id milan | Another user's IDs |
groups | Just the group names |
adduserCreate a user (Debian/Ubuntu friendly wrapper). sudo adduser [options] name
| Usage / option | What it does |
|---|---|
adduser milan | Create a user with home folder (asks for a password) |
adduser milan sudo | Add an existing user to a group |
--disabled-password | No password (log in with SSH keys) |
--comment "" | Skip the full-name questions (old name: --gecos) |
--home /srv/app | Custom home folder |
--shell /bin/zsh | Login shell |
--system | System account for a service |
--ingroup www-data | Primary group |
Other distros use useradd -m -s /bin/bash name instead.
usermodChange an existing user. sudo usermod [options] user
| Option | What it does |
|---|---|
-aG sudo | Append to group(s) (log out/in to apply) |
-G a,b | Set the groups (⚠ without -a removes all others) |
-s /bin/zsh | Change the login shell |
-l newname | Rename the account |
-d /new/home -m | New home folder and move the files |
-L / -U | Lock / unlock the account |
-e 2026-12-31 | Account expires on that date |
passwdChange a password. passwd [options] [user]
| Option | What it does |
|---|---|
passwd | Change your own password |
sudo passwd milan | Set another user's password |
-l / -u | Lock / unlock the password |
-e | Force a new password at next login |
-d | Remove the password (⚠ no password needed) |
-S | Show the password status |
suSwitch to another user. su [options] [user]
| Option | What it does |
|---|---|
su - or su -l | Become root with a full login environment |
su - milan | Become another user |
-c "command" | Run one command as that user |
-s /bin/bash | Use a specific shell |
ipShow and change network settings (Linux). ip [options] object command
| Usage / option | What it does |
|---|---|
ip a (ip addr) | All interfaces and their IP addresses |
ip a show eth0 | One interface |
ip -br a | Brief: one line per interface |
ip -4 a / ip -6 a | Only IPv4 / IPv6 |
ip r (ip route) | Routing table, including the default gateway |
ip link | Interfaces and their state (UP / DOWN, MAC) |
sudo ip link set eth0 up | Bring an interface up (down to disable) |
ip neigh | ARP table: other devices on the network |
sudo ip addr add 192.168.1.50/24 dev eth0 | Add an IP address (until reboot) |
-c | Coloured output |
-j -p | JSON, pretty-printed |
pingCheck whether a host answers. ping [options] host (Linux / macOS)
| Option | What it does |
|---|---|
-c 4 | Send 4 pings and stop (otherwise runs until Ctrl + C) |
-i 0.5 | Wait 0.5 s between pings |
-W 2 | Wait at most 2 s for each reply |
-w 10 | Stop after 10 seconds in total (Linux) |
-s 1400 | Packet size in bytes |
-4 / -6 | Force IPv4 / IPv6 |
-q | Quiet: only the summary |
-D | Print timestamps (Linux) |
-I eth0 | Use a specific interface |
-t 64 | TTL on Linux (on macOS -t is a timeout in seconds) |
curlTransfer data with URLs: download files, call APIs. curl [options] URL
| Option | What it does |
|---|---|
-o file | Save to a file with that name |
-O | Save with the name from the URL |
-L | Follow redirects |
-I | Headers only (HEAD request) |
-i | Include response headers in the output |
-v | Verbose: show the full request and response |
-s / -sS | Silent / silent but still show errors |
-f, --fail | Exit with an error on HTTP 4xx/5xx |
-X POST | HTTP method (PUT, DELETE, PATCH…) |
-H "Authorization: Bearer $TOKEN" | Add a header |
-d '{"a":1}' | Send data (makes it a POST) |
--json '{"a":1}' | Send JSON with the right headers (curl 7.82+) |
-F "file=@photo.jpg" | Upload a file as a form |
-u user:pass | Basic authentication |
-k | Ignore TLS certificate errors (testing only!) |
-C - | Resume a broken download |
--max-time 10 | Give up after 10 seconds |
--retry 3 | Retry on temporary errors |
-w "%{http_code}\n" | Print details such as the status code |
-b / -c cookies.txt | Send / save cookies |
-x http://proxy:8080 | Use a proxy |
--compressed | Ask for and decompress gzip/brotli responses |
Windows 10+ has real curl too (in PowerShell type curl.exe, because curl is an alias there).
wgetDownload files from the web. wget [options] URL
| Option | What it does |
|---|---|
-O file | Save under another name (-O - = print to screen) |
-P folder | Save into a folder |
-c | Continue a partial download |
-q | Quiet |
-b | Download in the background (log in wget-log) |
-i urls.txt | Download every URL in a file |
-r -np -l 2 | Recursive, not to the parent, 2 levels deep |
--mirror | Mirror a website |
--limit-rate=1m | Limit the speed |
-U "Mozilla/5.0" | Set the user agent |
--no-check-certificate | Ignore TLS errors (testing only!) |
ssShow network connections and listening ports (replaces netstat on Linux). ss [options]
| Option | What it does |
|---|---|
-t / -u | TCP / UDP |
-l | Only listening sockets |
-n | Numbers instead of names (faster) |
-p | Show the process using each socket (sudo for all) |
-a | All sockets |
-4 / -6 | IPv4 / IPv6 only |
-s | Summary statistics |
-x | Unix sockets |
state established | Only open connections |
Classic combo: sudo ss -tulpn (TCP + UDP, listening, process, numeric). Find a port: ss -ltnp | grep :3000.
digDNS lookup. dig [@server] name [type] [+options]
| Usage / option | What it does |
|---|---|
dig example.com | A record (IPv4) with full details |
+short | Only the answer |
dig example.com MX | Mail servers (AAAA, TXT, NS, CNAME, SOA…) |
@1.1.1.1 | Ask a specific DNS server |
-x 8.8.8.8 | Reverse lookup (IP → name) |
+trace | Follow the lookup from the root servers |
+noall +answer | Only the answer section |
nslookupDNS lookup (Linux / macOS; on Windows see the Command Prompt sheet). nslookup [-option] name [server]
| Usage / option | What it does |
|---|---|
nslookup example.com | IP addresses of a name |
nslookup example.com 1.1.1.1 | Ask a specific DNS server |
-type=MX | Record type: MX, TXT, NS, AAAA, CNAME, SOA |
nslookup 8.8.8.8 | Reverse lookup |
nslookup | Interactive mode (set type=mx, exit) |
dig gives more detailed answers and is easier to script.
hostnameShow or set the computer name. hostname [options]
| Option | What it does |
|---|---|
hostname | The host name |
-I | All IP addresses of this machine (Linux) |
-i | IP address the name resolves to |
-f | Full domain name (FQDN) |
-s | Short name |
sudo hostnamectl set-hostname pi4 | Change it permanently (systemd) |
tarPack and unpack .tar, .tar.gz, .tar.xz archives. tar [options] [files]
| Option | What it does |
|---|---|
-c | Create an archive |
-x | eXtract an archive |
-t | lisT the contents |
-f file | The archive File (always last of the letters) |
-v | Verbose: show every file |
-z | gzip (.tar.gz, .tgz) |
-j | bzip2 (.tar.bz2) |
-J | xz (.tar.xz) |
-a | Pick the compression from the file extension (when creating) |
-C folder | Extract into / create from that folder |
--exclude="node_modules" | Skip matching files |
--strip-components=1 | Drop the top folder when extracting |
-p | Keep permissions |
-k | Don't overwrite existing files |
-r | Append files to an existing archive |
Remember: tar -czvf out.tar.gz folder (create zipped) · tar -xzvf file.tar.gz (extract). Modern tar detects compression when extracting: tar -xf file.tar.xz.
zipCreate .zip files. zip [options] archive.zip files…
| Option | What it does |
|---|---|
-r | Include folders recursively |
-q | Quiet |
-9 / -0 | Best compression / no compression (store) |
-e | Encrypt with a password |
-x "*.git*" | Exclude matching files |
-u | Update: add new/changed files only |
-d | Delete files from the archive |
-m | Move files into the zip (delete originals) |
-j | Junk paths: store files without folders |
unzipExtract .zip files. unzip [options] archive.zip
| Option | What it does |
|---|---|
-l | List the contents |
-d folder | Extract into a folder |
-o | Overwrite without asking |
-n | Never overwrite |
-q | Quiet |
-j | Ignore folders inside the zip |
-t | Test the archive for errors |
-x "*.txt" | Skip matching files |
unzip file.zip "docs/*" | Extract only some files |
historyShow and reuse previous commands (Bash). history [options]
| Usage / option | What it does |
|---|---|
history | Numbered list of commands |
history 20 | Last 20 commands |
history | grep docker | Search the history |
-c | Clear the history of this session |
-d 42 | Delete entry 42 |
-w | Write the history to ~/.bash_history now |
!42 | Run command number 42 again |
!! / !$ | Last command / its last argument |
!git | Last command starting with "git" |
^old^new | Repeat the last command with a word replaced |
Ctrl + R | Search interactively |
Nothing on this sheet matches “”.