A reference of useful but under-used terminal commands, most of which ship with standard Linux distributions. Run man <command> for full documentation.
| Command | What it does | Example |
|---|---|---|
stat | Shows detailed file metadata: size, permissions, timestamps, inode | stat report.pdf |
file | Identifies a file's actual type regardless of its extension | file mystery.bin |
mktemp | Safely creates a unique temporary file or directory | tmp=$(mktemp -d) |
truncate | Shrinks or extends a file to an exact size | truncate -s 0 app.log |
shred | Overwrites a file before deleting so it is hard to recover | shred -u secrets.txt |
install | Copies a file and sets owner, mode, and destination in one step | install -m 755 app /usr/local/bin |
ln -s | Creates a symbolic link pointing at another file or directory | ln -s /var/log/app current-log |
readlink | Resolves where a symlink actually points | readlink -f current-log |
basename / dirname | Extracts the filename or directory part of a path | basename /etc/ssh/sshd_config |
tree | Prints a directory hierarchy as an indented tree | tree -L 2 /etc |
du | Measures disk usage per directory | du -sh */ | sort -h |
findmnt | Lists mounted filesystems in a readable tree | findmnt -t ext4 |
rename | Batch-renames files using a pattern | rename 's/.jpeg/.jpg/' *.jpeg |
| Command | What it does | Example |
|---|---|---|
tac | Prints a file in reverse line order — cat backwards | tac access.log | less |
rev | Reverses the characters on each line | echo hello | rev |
column | Aligns delimited text into neat columns | column -t -s, data.csv |
comm | Compares two sorted files: lines unique to each, lines shared | comm -12 old.txt new.txt |
join | Joins two sorted files on a common field, like a database join | join ids.txt names.txt |
paste | Merges files side by side, line by line | paste names.txt emails.txt |
cut | Extracts columns or character ranges from each line | cut -d: -f1 /etc/passwd |
tr | Translates or deletes characters in a stream | tr 'a-z' 'A-Z' < notes.txt |
fold | Wraps long lines at a fixed width | fold -w 80 -s essay.txt |
nl | Numbers the lines of a file | nl -ba script.sh |
shuf | Shuffles lines randomly, or picks a random sample | shuf -n 5 wordlist.txt |
split | Splits a large file into chunks by lines or size | split -l 1000 big.log part_ |
csplit | Splits a file at lines matching a pattern | csplit book.txt /^Chapter/ '{*}' |
expand / unexpand | Converts tabs to spaces, or spaces to tabs | expand -t 4 code.py |
look | Finds lines beginning with a string in a sorted file (fast dictionary lookup) | look micro /usr/share/dict/words |
diff -u | Shows differences between files in unified patch format | diff -u old.conf new.conf |
strings | Extracts readable text from binary files | strings program.bin | grep version |
iconv | Converts text between character encodings | iconv -f latin1 -t utf8 old.txt |
wc | Counts lines, words, and bytes | wc -l *.py |
| Command | What it does | Example |
|---|---|---|
watch | Re-runs a command at intervals and displays the output | watch -n 2 df -h |
timeout | Runs a command but kills it after a time limit | timeout 30s ./flaky.sh |
pgrep / pkill | Finds or signals processes by name instead of PID | pkill -f "python server.py" |
nohup | Keeps a command running after you log out | nohup ./backup.sh & |
disown | Detaches a background job from the shell so it survives exit | disown %1 |
nice / renice | Starts or adjusts a process at lower CPU priority | nice -n 19 ./heavy-job.sh |
ionice | Sets a process's disk I/O priority | ionice -c 3 tar czf backup.tgz /home |
pstree | Shows running processes as a parent–child tree | pstree -p |
pidof | Returns the PID of a named program | pidof nginx |
lsof | Lists open files, including which process holds a port | lsof -i :8080 |
fuser | Shows which processes are using a file, mount, or port | fuser -v /mnt/usb |
at | Schedules a one-off command for later, without cron | echo "reboot" | at 03:00 |
setsid | Runs a command in a new session, fully detached from the terminal | setsid ./daemon.sh |
time | Measures how long a command takes to run | time make |
| Command | What it does | Example |
|---|---|---|
uname -a | Prints kernel version and architecture | uname -a |
lscpu | Summarises CPU model, cores, and cache | lscpu |
lsblk | Lists disks and partitions as a tree | lsblk -f |
lsusb / lspci | Lists connected USB and PCI devices | lsusb |
free | Shows memory and swap usage | free -h |
vmstat | Reports memory, swap, I/O, and CPU activity over time | vmstat 1 5 |
uptime | Shows time since boot and load averages | uptime |
last | Shows history of logins, reboots, and shutdowns | last -n 10 |
w | Shows who is logged in and what they are running | w |
getent | Queries system databases (users, groups, hosts) the way the OS does | getent passwd alice |
dmesg | Prints kernel messages — useful after plugging in hardware | dmesg --follow |
journalctl | Queries systemd logs by service, time, or priority | journalctl -u nginx --since today |
hostnamectl | Shows or sets the hostname plus OS and kernel info | hostnamectl |
timedatectl | Shows or sets time, date, and timezone | timedatectl |
| Command | What it does | Example |
|---|---|---|
ss | Inspects sockets and listening ports (modern netstat) | ss -tulpn |
ip | Shows or configures interfaces, addresses, and routes | ip addr show |
dig | Queries DNS records in detail | dig +short example.com MX |
nc (netcat) | Reads and writes raw network connections; quick port tests | nc -zv host.local 22 |
curl | Transfers data over HTTP and many other protocols | curl -I https://example.com |
wget -c | Downloads files, resuming interrupted transfers | wget -c big.iso |
traceroute | Shows each network hop to a destination | traceroute example.com |
arp | Shows the table mapping IP addresses to MAC addresses | arp -a |
rsync | Syncs files locally or remotely, copying only what changed | rsync -avz docs/ server:/backup/ |
| Command | What it does | Example |
|---|---|---|
tee | Writes output to a file and passes it along the pipe at the same time | make 2>&1 | tee build.log |
xargs | Builds and runs commands from piped input | find . -name "*.tmp" | xargs rm |
script | Records your whole terminal session to a file | script session.log |
pushd / popd | Keeps a stack of directories so you can jump back | pushd /etc && popd |
dirs | Shows the current directory stack | dirs -v |
yes | Repeats a string forever — auto-confirms prompts | yes | apt-get install pkg |
seq | Generates sequences of numbers | seq 1 2 20 |
printf | Formats output precisely, more predictably than echo | printf "%05d\n" 42 |
type | Tells you whether a command is a binary, alias, or shell builtin | type ls |
which | Shows the full path of the binary that would run | which python3 |
alias | Defines shortcuts for longer commands | alias ll='ls -alF' |
history | Lists past commands; pair with !n to re-run one | history | grep ssh |
fc | Opens your last command in an editor to fix and re-run it | fc |
read | Reads user input into a variable in scripts | read -p "Name: " name |
| Command | What it does | Example |
|---|---|---|
cal | Prints a calendar in the terminal | cal -3 |
date | Prints or formats the current date and time | date +%Y-%m-%d |
bc | Arbitrary-precision calculator | echo "scale=4; 22/7" | bc |
factor | Prints the prime factorisation of a number | factor 1234567 |
units | Converts between units of measurement | units "60 mph" "km/h" |
sleep | Pauses for a given duration — useful in scripts and loops | sleep 5m |
md5sum / sha256sum | Computes checksums to verify file integrity | sha256sum download.iso |
base64 | Encodes or decodes data as base64 | base64 -d secret.b64 |
xxd | Produces a hex dump of a file, or reverses one back to binary | xxd header.bin | head |
env | Lists environment variables, or runs a command with a modified set | env LANG=C sort file.txt |
whoami / id | Shows your username, UID, and group memberships | id |
tput | Controls terminal features like colours and cursor position | tput setaf 2; echo OK |
Nearly all of these are part of coreutils, util-linux, procps, or iproute2 and come preinstalled on most Linux distributions.