find . -type f -size +100M

Files List files larger than 100 MB under the current directory · guide

find . -type f -mtime -1

Files Find files modified in the last 24 hours · guide

find . -type f -mtime +30

Files Find files not modified for more than 30 days · guide

find . -iname "*.jpg"

Files Find files by name, ignoring case · guide

find . -name node_modules -prune -o -type f -name "*.js" -print

Files Find .js files while skipping node_modules · guide

find . -type f -name "*.tmp" -delete

Files Delete all .tmp files below the current directory (careful: run without -delete first) · guide

find . -type f -name "*.sh" -exec chmod +x {} +

Files Make every .sh file executable · guide

find . -type f -print0 | xargs -0 grep -l "TODO"

Files List files containing TODO, safe for spaces in names · guide

find . -maxdepth 1 -type f

Files List files in the current directory only, no subdirectories · guide

find . -type f -printf '%s %p\n' | sort -n | tail -10

Files Show the 10 largest files with sizes in bytes (GNU find) · guide

find . -type l -xtype l

Files Find broken symbolic links (GNU find) · guide

ls -lhS

Files List files sorted by size, largest first, with readable sizes

ls -lt | head

Files Show the 10 most recently modified entries

mkdir -p project/{src,tests,docs}

Files Create a directory and several subdirectories at once

ln -s /path/to/target linkname

Files Create a symbolic link

stat -c '%a %U:%G %n' file

Files Show a file's octal permissions and owner (GNU stat) · guide

chmod 644 file.txt

Files Set normal file permissions: owner read/write, everyone else read · guide

chmod 755 script.sh

Files Make a script executable by everyone, writable only by the owner · guide

chmod 600 ~/.ssh/id_ed25519

Files Make a private key readable only by you · guide

chmod -R u=rwX,go=rX dir/

Files Set 755 on directories and 644 on files recursively · guide

sudo chown -R www-data:www-data /var/www/site

Files Change owner and group of a whole directory tree (careful: check the path) · guide

rsync -avn src/ dest/

Files Preview what rsync would copy, without copying (dry run) · guide

diff -u old.conf new.conf

Files Show differences between two files in unified format

diff -rq dir1/ dir2/

Files List files that differ between two directories

sha256sum -c SHA256SUMS

Files Verify files against a list of SHA-256 checksums

file mystery.bin

Files Guess what type of data a file contains

grep -rn "pattern" .

Text Search all files below the current directory, with line numbers · guide

grep -ri "error" /var/log/app/

Text Search a directory recursively, ignoring case · guide

grep -Ev '^(#|$)' file.conf

Text Show a config file without comments and blank lines · guide

grep -c "404" access.log

Text Count lines that contain 404 · guide

grep -oE '[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+' access.log | sort -u

Text Extract unique IPv4 addresses from a file · guide

grep -rl "oldname" --include="*.php" .

Text List PHP files that contain a string · guide

grep -C 3 "Exception" app.log

Text Show each match with 3 lines of context · guide

sed 's/old/new/g' file

Text Replace every occurrence of old with new and print the result · guide

sed -i.bak 's/old/new/g' file

Text Replace text in place, keeping file.bak as a backup (GNU and macOS) · guide

sed -n '10,20p' file

Text Print lines 10 to 20 · guide

sed '/^$/d' file

Text Delete empty lines · guide

sed 's/[[:space:]]*$//' file

Text Remove trailing whitespace from every line · guide

awk '{print $1}' access.log

Text Print the first column of each line · guide

awk -F: '{print $1}' /etc/passwd

Text List all usernames on the system · guide

awk '{s += $NF} END {print s}' file

Text Sum the last column · guide

awk -F, 'NR > 1 {print $2}' data.csv

Text Print the second column of a simple CSV, skipping the header · guide

awk '!seen[$0]++' file

Text Remove duplicate lines but keep the original order · guide

sort file | uniq -c | sort -rn | head

Text Show the most common lines with their counts · guide

sort -u file

Text Sort lines and remove duplicates

cut -d, -f1,3 data.csv

Text Print the first and third comma-separated fields

wc -l file

Text Count the lines in a file

tr -d '\r' < dos.txt > unix.txt

Text Convert Windows line endings to Unix

tail -f /var/log/syslog

Text Follow a log file as new lines are written

comm -12 <(sort a.txt) <(sort b.txt)

Text Show lines that appear in both files · guide

diff <(sort a.txt) <(sort b.txt)

Text Compare two files regardless of line order · guide

seq 1 10 | paste -sd+ | bc

Text Add up a list of numbers · guide

tar -czf archive.tar.gz dir/

Archives Create a gzip-compressed tar archive of a directory

tar -xzf archive.tar.gz

Archives Extract a .tar.gz archive into the current directory

tar -xzf archive.tar.gz -C /target/dir

Archives Extract a .tar.gz archive into another directory

tar -tzf archive.tar.gz

Archives List the contents of a .tar.gz archive without extracting

tar -cJf archive.tar.xz dir/

Archives Create an xz-compressed tar archive (smaller, slower)

tar -czf backup-$(date +%F).tar.gz dir/

Archives Create an archive with today's date in the name

tar -czf site.tar.gz --exclude='*.log' site/

Archives Archive a directory while excluding log files

zip -r archive.zip dir/

Archives Create a zip archive of a directory

unzip archive.zip -d target/

Archives Extract a zip file into a directory

gzip -k file.log

Archives Compress a file and keep the original

zcat file.log.gz | grep error

Archives Search a gzip-compressed file without extracting it

uname -a

System Show kernel version and system architecture

cat /etc/os-release

System Show which Linux distribution and version is installed

uptime

System Show how long the system has been up and the load average

free -h

System Show memory and swap usage in readable units

date +%F_%H-%M-%S

System Print a timestamp suitable for file names

date -d @1761350400

System Convert a Unix timestamp to a readable date (GNU date)

systemctl status nginx

System Show whether a service is running, with recent log lines · guide

sudo systemctl restart nginx

System Restart a systemd service · guide

systemctl list-units --type=service --state=failed

System List services that have failed · guide

journalctl -u nginx -f

System Follow a service's log in real time · guide

journalctl -p err -b

System Show error messages since the last boot · guide

crontab -l

System List your scheduled cron jobs

echo $PATH | tr ':' '\n'

System Show each directory in your PATH on its own line

type -a python3

System Show every location and alias a command name resolves to · guide

source ~/.bashrc

System Reload your Bash settings in the current shell · guide

ps aux --sort=-%mem | head

Processes Show the processes using the most memory · guide

ps aux --sort=-%cpu | head

Processes Show the processes using the most CPU · guide

pgrep -a nginx

Processes Find processes by name and show their command lines · guide

ps aux | grep '[n]ginx'

Processes Search the process list without matching the grep itself · guide

kill 1234

Processes Ask process 1234 to exit cleanly (SIGTERM) · guide

kill -9 1234

Processes Force-kill a process that ignores SIGTERM (careful: no cleanup) · guide

pkill -f "python3 app.py"

Processes Stop processes whose command line matches (careful: check with pgrep -f first) · guide

nohup ./job.sh > job.log 2>&1 &

Processes Run a job in the background that keeps running after logout · guide

jobs -l

Processes List background jobs in this shell with their PIDs · guide

disown -h %1

Processes Keep job 1 running when the shell exits · guide

nice -n 10 ./heavy.sh

Processes Run a command with lower CPU priority · guide

renice -n 10 -p 1234

Processes Lower the priority of a running process · guide

timeout 10s ./script.sh

Processes Run a command and stop it if it takes longer than 10 seconds

ip -br addr

Network Show IP addresses of all network interfaces, one line each

ip route

Network Show the routing table, including the default gateway

ss -tulpn

Network List listening TCP and UDP ports and the processes behind them (use sudo to see all)

ping -c 4 example.com

Network Send 4 pings to test connectivity

curl -I https://example.com

Network Fetch only the HTTP response headers

curl -sS -o /dev/null -w '%{http_code}\n' https://example.com

Network Print only the HTTP status code of a URL

curl -L -O https://example.com/file.tar.gz

Network Download a file, following redirects and keeping its name

dig +short example.com

Network Look up the IP address of a domain name

ssh-keygen -t ed25519 -C "you@laptop"

Network Create a new Ed25519 SSH key pair · guide

ssh-copy-id user@host

Network Install your public key on a server for password-free login · guide

ssh -N -L 3307:127.0.0.1:3306 user@host

Network Forward local port 3307 to MySQL on a remote server · guide

ssh -J bastion user@internal-host

Network Connect to a private host through a jump host · guide

ssh -G host

Network Show the SSH settings that apply to a host, without connecting · guide

ssh-keygen -R host

Network Remove an old host key from known_hosts · guide

rsync -avz --progress src/ user@host:/path/dest/

Network Copy a directory to a server, sending only changes · guide

scp file.txt user@host:/tmp/

Network Copy a file to a server · guide

df -h

Disk Show free space on all mounted filesystems

df -h /

Disk Show free space on the root filesystem

du -sh *

Disk Show the size of each item in the current directory

du -h -d 1 | sort -h

Disk Show directory sizes one level deep, smallest to largest

du -ah . | sort -rh | head -20

Disk Show the 20 biggest files and directories below here

df -i

Disk Show inode usage, useful when a disk is 'full' but has free space

lsblk

Disk List disks and partitions in a tree

findmnt

Disk Show mounted filesystems in a tree

sudo journalctl --vacuum-size=200M

Disk Shrink the systemd journal to 200 MB (careful: deletes old logs)

history | grep ssh

History Search your command history for ssh commands · guide

!!

History Repeat the previous command · guide

sudo !!

History Repeat the previous command with sudo · guide

!$

History Reuse the last argument of the previous command · guide

!ssh:p

History Print the most recent command starting with ssh, without running it · guide

^typo^fixed

History Rerun the previous command with the first 'typo' replaced by 'fixed' · guide

fc

History Open the previous command in your editor and run it after saving · guide

history -d 1234

History Delete entry 1234 from history (then history -w to save) · guide

HISTTIMEFORMAT='%F %T ' history 10

History Show the last 10 commands with timestamps · guide

history | awk '{print $2}' | sort | uniq -c | sort -rn | head

History Show the commands you use most often · guide

PS1='\u@\h:\w\$ '

Prompt Classic prompt: user, host and current directory · guide

PS1='\W\$ '

Prompt Minimal prompt showing only the current folder name · guide

PS1='\[\e[1;32m\]\u@\h\[\e[0m\]:\[\e[1;34m\]\w\[\e[0m\]\$ '

Prompt Colored prompt with green user@host and blue directory · guide

PS1='[\t] \w\$ '

Prompt Prompt with the current time · guide

PS1='\n\w\n\$ '

Prompt Two-line prompt with the path above the input line · guide

PROMPT_DIRTRIM=2

Prompt Show only the last 2 directories of long paths in \w · guide

echo "$PS1"

Prompt Show your current prompt definition · guide

set -euo pipefail

Scripting Stop a script on errors, unset variables and failed pipes · guide

bash -n script.sh

Scripting Check a script for syntax errors without running it · guide

bash -x script.sh

Scripting Run a script and print each command as it executes · guide

for f in *.txt; do echo "$f"; done

Scripting Loop over files safely, even with spaces in names · guide

for i in {1..10}; do echo "$i"; done

Scripting Loop over a range of numbers · guide

while IFS= read -r line; do echo "$line"; done < file

Scripting Read a file line by line · guide

for f in *.jpeg; do mv -n -- "$f" "${f%.jpeg}.jpg"; done

Scripting Change the extension of many files · guide

[[ -f file ]] && echo exists

Scripting Check whether a file exists · guide

command -v git >/dev/null || echo "git not installed"

Scripting Check whether a command is available · guide

read -r -p "Continue? [y/N] " ans

Scripting Ask the user a question and store the answer · guide

echo "${var:-default}"

Scripting Use a default value when a variable is unset or empty · guide

cmd > /dev/null 2>&1

Scripting Silence both output and errors of a command · guide

cmd 2>&1 | tee -a run.log

Scripting Show output and append it to a log file · guide

cat urls.txt | xargs -n 1 -P 4 curl -sO

Scripting Download URLs from a list, 4 at a time · guide

mapfile -t lines < file

Scripting Read a file into an array, one line per element · guide

echo "${#arr[@]}"

Scripting Print the number of elements in an array · guide

declare -A map=([key]=value)

Scripting Create an associative array (string keys) · guide

echo "${path##*/}"

Scripting Get the file name from a path without calling basename · guide

echo "${f%.*}"

Scripting Strip the last extension from a file name · guide

echo "${s//old/new}"

Scripting Replace every match in a string variable · guide

echo "${s^^}"

Scripting Convert a variable to upper case (use ,, for lower case) · guide

tar -xzf archive.tar.gz --strip-components=1

Archives Extract without the top-level folder · guide

tar -C dir -czf archive.tar.gz .

Archives Archive a directory's contents without its parent path · guide

tar --zstd -cf archive.tar.zst dir/

Archives Create a zstd-compressed tarball (fast, good ratio) · guide

unzip -l archive.zip

Archives List the contents of a zip file without extracting · guide

zgrep "error" app.log.gz

Archives Search a gzipped log without unpacking it · guide

df -h -x tmpfs -x devtmpfs

Disk Show free space on real disks only · guide

du -sh --apparent-size file

Disk Show the byte size like ls instead of allocated blocks · guide

du --inodes -d 1 | sort -n

Disk Count files per directory to find what is using up inodes · guide

ncdu -x /

Disk Browse disk usage interactively, staying on one filesystem · guide

journalctl --disk-usage

Disk Show how much space the systemd journal uses · guide

sudo lsof +L1

Disk Find deleted files still held open (space not yet freed) · guide

curl -fsSL --retry 3 -o out.html https://example.com

Network Download quietly, follow redirects, fail on HTTP errors and retry · guide

curl -s -o /dev/null -w '%{time_total}\n' https://example.com

Network Time how long a request takes · guide

curl -s -H 'Content-Type: application/json' -d '{"name":"alice"}' https://httpbin.org/post

Network POST a JSON body to an API · guide

curl -C - -O https://example.com/big.iso

Network Resume an interrupted download with curl · guide

wget -c https://example.com/big.iso

Network Resume an interrupted download with wget · guide

curl -s https://httpbin.org/json | jq .

Network Pretty-print a JSON API response · guide

export PATH="$HOME/bin:$PATH"

System Add ~/bin to the front of PATH for this session · guide

set -a; source .env; set +a

System Load a .env file and export every variable in it · guide

TZ=UTC date

System Show the current time in another time zone for one command · guide

env -i /bin/sh -c ./job.sh

System Run a script with an almost empty environment, like cron does · guide

flock -n /tmp/job.lock ./job.sh

System Skip a run if the previous one still holds the lock (no overlap) · guide

run-parts --test /etc/cron.daily

System List which cron.daily scripts would actually run · guide

Commands marked "careful" change or delete files: read them before you press Enter. Most examples assume GNU tools as found on Linux; macOS versions of sed, find and date differ slightly.