find . -type f -size +100MFiles List files larger than 100 MB under the current directory · guide
find . -type f -mtime -1Files Find files modified in the last 24 hours · guide
find . -type f -mtime +30Files 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" -printFiles Find .js files while skipping node_modules · guide
find . -type f -name "*.tmp" -deleteFiles 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 fFiles List files in the current directory only, no subdirectories · guide
find . -type f -printf '%s %p\n' | sort -n | tail -10Files Show the 10 largest files with sizes in bytes (GNU find) · guide
find . -type l -xtype lFiles Find broken symbolic links (GNU find) · guide
ls -lhSFiles List files sorted by size, largest first, with readable sizes
ls -lt | headFiles 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 linknameFiles Create a symbolic link
stat -c '%a %U:%G %n' fileFiles Show a file's octal permissions and owner (GNU stat) · guide
chmod 644 file.txtFiles Set normal file permissions: owner read/write, everyone else read · guide
chmod 755 script.shFiles Make a script executable by everyone, writable only by the owner · guide
chmod 600 ~/.ssh/id_ed25519Files 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/siteFiles 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.confFiles Show differences between two files in unified format
diff -rq dir1/ dir2/Files List files that differ between two directories
sha256sum -c SHA256SUMSFiles Verify files against a list of SHA-256 checksums
file mystery.binFiles 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.confText Show a config file without comments and blank lines · guide
grep -c "404" access.logText Count lines that contain 404 · guide
grep -oE '[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+' access.log | sort -uText 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.logText Show each match with 3 lines of context · guide
sed 's/old/new/g' fileText Replace every occurrence of old with new and print the result · guide
sed -i.bak 's/old/new/g' fileText Replace text in place, keeping file.bak as a backup (GNU and macOS) · guide
sed -n '10,20p' fileText Print lines 10 to 20 · guide
sed '/^$/d' fileText Delete empty lines · guide
sed 's/[[:space:]]*$//' fileText Remove trailing whitespace from every line · guide
awk '{print $1}' access.logText Print the first column of each line · guide
awk -F: '{print $1}' /etc/passwdText List all usernames on the system · guide
awk '{s += $NF} END {print s}' fileText Sum the last column · guide
awk -F, 'NR > 1 {print $2}' data.csvText Print the second column of a simple CSV, skipping the header · guide
awk '!seen[$0]++' fileText Remove duplicate lines but keep the original order · guide
sort file | uniq -c | sort -rn | headText Show the most common lines with their counts · guide
sort -u fileText Sort lines and remove duplicates
cut -d, -f1,3 data.csvText Print the first and third comma-separated fields
wc -l fileText Count the lines in a file
tr -d '\r' < dos.txt > unix.txtText Convert Windows line endings to Unix
tail -f /var/log/syslogText 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+ | bcText 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.gzArchives Extract a .tar.gz archive into the current directory
tar -xzf archive.tar.gz -C /target/dirArchives Extract a .tar.gz archive into another directory
tar -tzf archive.tar.gzArchives 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.logArchives Compress a file and keep the original
zcat file.log.gz | grep errorArchives Search a gzip-compressed file without extracting it
uname -aSystem Show kernel version and system architecture
cat /etc/os-releaseSystem Show which Linux distribution and version is installed
uptimeSystem Show how long the system has been up and the load average
free -hSystem Show memory and swap usage in readable units
date +%F_%H-%M-%SSystem Print a timestamp suitable for file names
date -d @1761350400System Convert a Unix timestamp to a readable date (GNU date)
systemctl status nginxSystem Show whether a service is running, with recent log lines · guide
sudo systemctl restart nginxSystem Restart a systemd service · guide
systemctl list-units --type=service --state=failedSystem List services that have failed · guide
journalctl -u nginx -fSystem Follow a service's log in real time · guide
journalctl -p err -bSystem Show error messages since the last boot · guide
crontab -lSystem List your scheduled cron jobs
echo $PATH | tr ':' '\n'System Show each directory in your PATH on its own line
type -a python3System Show every location and alias a command name resolves to · guide
source ~/.bashrcSystem Reload your Bash settings in the current shell · guide
ps aux --sort=-%mem | headProcesses Show the processes using the most memory · guide
ps aux --sort=-%cpu | headProcesses Show the processes using the most CPU · guide
pgrep -a nginxProcesses 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 1234Processes Ask process 1234 to exit cleanly (SIGTERM) · guide
kill -9 1234Processes 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 -lProcesses List background jobs in this shell with their PIDs · guide
disown -h %1Processes Keep job 1 running when the shell exits · guide
nice -n 10 ./heavy.shProcesses Run a command with lower CPU priority · guide
renice -n 10 -p 1234Processes Lower the priority of a running process · guide
timeout 10s ./script.shProcesses Run a command and stop it if it takes longer than 10 seconds
ip -br addrNetwork Show IP addresses of all network interfaces, one line each
ip routeNetwork Show the routing table, including the default gateway
ss -tulpnNetwork List listening TCP and UDP ports and the processes behind them (use sudo to see all)
ping -c 4 example.comNetwork Send 4 pings to test connectivity
curl -I https://example.comNetwork Fetch only the HTTP response headers
curl -sS -o /dev/null -w '%{http_code}\n' https://example.comNetwork Print only the HTTP status code of a URL
curl -L -O https://example.com/file.tar.gzNetwork Download a file, following redirects and keeping its name
dig +short example.comNetwork 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@hostNetwork Install your public key on a server for password-free login · guide
ssh -N -L 3307:127.0.0.1:3306 user@hostNetwork Forward local port 3307 to MySQL on a remote server · guide
ssh -J bastion user@internal-hostNetwork Connect to a private host through a jump host · guide
ssh -G hostNetwork Show the SSH settings that apply to a host, without connecting · guide
ssh-keygen -R hostNetwork 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 -hDisk 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 -hDisk Show directory sizes one level deep, smallest to largest
du -ah . | sort -rh | head -20Disk Show the 20 biggest files and directories below here
df -iDisk Show inode usage, useful when a disk is 'full' but has free space
lsblkDisk List disks and partitions in a tree
findmntDisk Show mounted filesystems in a tree
sudo journalctl --vacuum-size=200MDisk Shrink the systemd journal to 200 MB (careful: deletes old logs)
history | grep sshHistory 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:pHistory Print the most recent command starting with ssh, without running it · guide
^typo^fixedHistory Rerun the previous command with the first 'typo' replaced by 'fixed' · guide
fcHistory Open the previous command in your editor and run it after saving · guide
history -d 1234History Delete entry 1234 from history (then history -w to save) · guide
HISTTIMEFORMAT='%F %T ' history 10History Show the last 10 commands with timestamps · guide
history | awk '{print $2}' | sort | uniq -c | sort -rn | headHistory 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=2Prompt Show only the last 2 directories of long paths in \w · guide
echo "$PS1"Prompt Show your current prompt definition · guide
set -euo pipefailScripting Stop a script on errors, unset variables and failed pipes · guide
bash -n script.shScripting Check a script for syntax errors without running it · guide
bash -x script.shScripting Run a script and print each command as it executes · guide
for f in *.txt; do echo "$f"; doneScripting Loop over files safely, even with spaces in names · guide
for i in {1..10}; do echo "$i"; doneScripting Loop over a range of numbers · guide
while IFS= read -r line; do echo "$line"; done < fileScripting Read a file line by line · guide
for f in *.jpeg; do mv -n -- "$f" "${f%.jpeg}.jpg"; doneScripting Change the extension of many files · guide
[[ -f file ]] && echo existsScripting 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] " ansScripting 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>&1Scripting Silence both output and errors of a command · guide
cmd 2>&1 | tee -a run.logScripting Show output and append it to a log file · guide
cat urls.txt | xargs -n 1 -P 4 curl -sOScripting Download URLs from a list, 4 at a time · guide
mapfile -t lines < fileScripting 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=1Archives 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.zipArchives List the contents of a zip file without extracting · guide
zgrep "error" app.log.gzArchives Search a gzipped log without unpacking it · guide
df -h -x tmpfs -x devtmpfsDisk Show free space on real disks only · guide
du -sh --apparent-size fileDisk Show the byte size like ls instead of allocated blocks · guide
du --inodes -d 1 | sort -nDisk 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-usageDisk Show how much space the systemd journal uses · guide
sudo lsof +L1Disk Find deleted files still held open (space not yet freed) · guide
curl -fsSL --retry 3 -o out.html https://example.comNetwork Download quietly, follow redirects, fail on HTTP errors and retry · guide
curl -s -o /dev/null -w '%{time_total}\n' https://example.comNetwork Time how long a request takes · guide
curl -s -H 'Content-Type: application/json' -d '{"name":"alice"}' https://httpbin.org/postNetwork POST a JSON body to an API · guide
curl -C - -O https://example.com/big.isoNetwork Resume an interrupted download with curl · guide
wget -c https://example.com/big.isoNetwork 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 +aSystem Load a .env file and export every variable in it · guide
TZ=UTC dateSystem Show the current time in another time zone for one command · guide
env -i /bin/sh -c ./job.shSystem Run a script with an almost empty environment, like cron does · guide
flock -n /tmp/job.lock ./job.shSystem Skip a run if the previous one still holds the lock (no overlap) · guide
run-parts --test /etc/cron.dailySystem 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.