Commands Reference

114 essential Unix/Linux commands with syntax, real-world examples, and persona tags. Search by name or keyword; filter for your role.

dev sysadmin infra

Navigation & File Operations

11 commands

ls

List directory contents.

devsysadmin

Syntax: ls [OPTIONS] [FILE...]

Examples

bash
ls -la /var/log          # permissions, sizes, hidden files
ls -lhS ~/Downloads      # human sizes, largest first
ls -lt app/              # sort by modification time
ls -d */                 # directories only in cwd

Pro Tip: Use ls -la instead of ls -l alone — missing dotfiles hides .env and .ssh config.

cd

Change the current working directory.

dev

Syntax: cd [DIRECTORY]

Examples

bash
cd /var/www/app
cd ..                    # parent directory
cd -                     # previous directory (toggle)
cd ~deploy               # another user's home (if permitted)

pwd

Print working directory (absolute path).

dev

Syntax: pwd [OPTIONS]

Examples

bash
pwd
pwd -P                   # resolve symlinks (physical path)
cd $(mktemp -d) && pwd     # confirm temp build dir

cp

Copy files or directories.

devsysadmin

Syntax: cp [OPTIONS] SOURCE... DEST

Examples

bash
cp nginx.conf nginx.conf.bak
cp -a /data/app/ /backup/app-$(date +%F)/   # archive mode preserves meta
cp -r src/ dist/src/
cp -n *.log /archive/    # no-clobber — skip existing

mv

Move or rename files.

devsysadmin

Syntax: mv [OPTIONS] SOURCE... DEST

Examples

bash
mv app.log app.log.1
# for deploys, prefer: ln -sfn releases/20250604 /opt/app/current
mv -i *.tmp /tmp/        # prompt before overwrite

rm

Remove files or directories.

devsysadmin

Syntax: rm [OPTIONS] FILE...

Examples

bash
rm stale.lock
rm -r build/ node_modules/   # recursive
rm -f /var/cache/app/*       # force — no prompt
rm -i important.db           # interactive — prefer this for risky paths

Pro Tip: Never alias rm to rm -i in scripts (CI breaks). Use rm -rf only with a literal path you typed.

Warning: Double-check paths and targets. Mistakes can delete data or take down services.

mkdir

Create directories.

dev

Syntax: mkdir [OPTIONS] DIRECTORY...

Examples

bash
mkdir -p src/components/ui
mkdir -m 750 /var/lib/myapp
install -d -o deploy -g deploy /opt/app/releases

rmdir

Remove empty directories.

dev

Syntax: rmdir [OPTIONS] DIRECTORY...

Examples

bash
rmdir empty_dir
rmdir -p a/b/c             # remove c, then parents if empty

Pro Tip: rmdir fails on non-empty dirs — use rm -r or find ... -delete for trees.

find

Search directory trees by name, type, time, size.

devsysadmininfra

Syntax: find PATH [EXPRESSION...]

Examples

bash
find /var/log -name '*.log' -mtime +30 -delete
find . -type f -name '*.py' -exec grep -l 'TODO' {} +
find / -xdev -size +1G 2>/dev/null   # large files, stay on one FS
find /opt -type l ! -exec test -e {} \; -print   # broken symlinks

locate

Fast filename search using a pre-built database (mlocate).

sysadmin

Syntax: locate [OPTIONS] PATTERN

Examples

bash
locate nginx.conf
locate '*.pem' | grep etc
sudo updatedb              # refresh DB after mass installs

Pro Tip: locate won't see files created minutes ago until updatedb runs (often nightly cron).

tree

Display directory hierarchy as a tree.

dev

Syntax: tree [OPTIONS] [DIRECTORY]

Examples

bash
tree -L 2 -d src/
tree -h --du /var/www      # sizes and disk usage
tree -I 'node_modules|__pycache__' .

File Viewing & Editing

8 commands

cat

Concatenate and print files to stdout.

dev

Syntax: cat [OPTIONS] [FILE...]

Examples

bash
cat /etc/os-release
cat file1 file2 > merged.txt
cat -n script.sh           # line numbers
cat -A weird.txt           # show $ end lines, tabs as ^I

Pro Tip: Don't cat huge logs into memory — use less or tail -f.

less

Pager for viewing files (scroll, search).

devsysadmin

Syntax: less [OPTIONS] FILE...

Examples

bash
less /var/log/syslog
less +F /var/log/app.log   # follow mode (like tail -f)
grep ERROR huge.log | less
journalctl -u nginx | less

Pro Tip: Inside less: /pattern search, n next, q quit, G end, g top.

more

Simple forward-only pager (legacy).

dev

Syntax: more [OPTIONS] FILE...

Examples

bash
more README.md
man ls | more

Pro Tip: Prefer less — supports backward scroll and search.

head

Print the first lines of files.

dev

Syntax: head [OPTIONS] [FILE...]

Examples

bash
head -n 20 access.log
head -c 1M image.bin | xxd   # inspect binary header
head -n 1 *.csv              # header row of each CSV

tail

Print the last lines; follow growing files.

devsysadmin

Syntax: tail [OPTIONS] [FILE...]

Examples

bash
tail -f /var/log/nginx/error.log
tail -n 100 deploy.log
tail -F rotated.log          # retry if file recreated

vim

Vi IMproved — modal text editor (also vi on minimal systems).

devsysadmin

Syntax: vim [OPTIONS] [FILE...]

Examples

bash
vim /etc/nginx/nginx.conf
vim +42 app.py             # jump to line 42
vim -o file1 file2         # horizontal splits
vim -d old.conf new.conf   # diff mode

Pro Tip: Esc then :wq save quit, :q! force quit. On servers without vim: nano or vi.

nano

Simple terminal text editor (beginner-friendly).

devsysadmin

Syntax: nano [OPTIONS] [FILE...]

Examples

bash
nano ~/.bashrc
sudo nano /etc/fstab
nano -l script.sh          # line numbers

wc

Count lines, words, bytes.

dev

Syntax: wc [OPTIONS] [FILE...]

Examples

bash
wc -l access.log
wc -c backup.tar.gz
find . -name '*.go' | xargs wc -l | tail -1

Permissions & Ownership

6 commands

chmod

Change file mode (permission bits).

sysadmindev

Syntax: chmod [OPTIONS] MODE FILE...

Examples

bash
chmod 600 ~/.ssh/id_rsa
chmod +x deploy.sh
chmod -R g+w /var/shared
chmod u+s /usr/local/bin/myhelper   # setuid

chown

Change file owner and group.

sysadmin

Syntax: chown [OPTIONS] OWNER[:GROUP] FILE...

Examples

bash
chown www-data:www-data -R /var/www
chown deploy:deploy app.log
chown root:root /usr/bin/special

chgrp

Change group ownership.

sysadmin

Syntax: chgrp [OPTIONS] GROUP FILE...

Examples

bash
chgrp docker /var/run/docker.sock
chgrp -R developers /opt/shared

umask

Set default permission mask for new files.

sysadmindev

Syntax: umask [MODE]

Examples

bash
umask
umask 027                  # new files 640, dirs 750
umask 077                  # private defaults

getfacl

Display POSIX ACLs on files.

sysadmin

Syntax: getfacl [OPTIONS] FILE...

Examples

bash
getfacl /data/shared
getfacl -R /nfs/mount | less

setfacl

Set POSIX ACL entries.

sysadmin

Syntax: setfacl [OPTIONS] FILE...

Examples

bash
setfacl -m u:alice:rwx /data/shared
setfacl -m g:eng:r-x /data/shared
setfacl -b file              # remove all ACLs

Process Management

11 commands

ps

Snapshot of running processes.

devsysadmininfra

Syntax: ps [OPTIONS]

Examples

bash
ps aux --sort=-%mem | head
ps -ef --forest
ps -p 1234 -o pid,cmd,%cpu,etime
ps -u deploy -f

top

Interactive live process viewer.

sysadmininfra

Syntax: top [OPTIONS]

Examples

bash
top
top -u nginx
top -o %CPU
top -bn1 | head -20        # batch mode for scripts

htop

Enhanced interactive process viewer.

devinfra

Syntax: htop [OPTIONS]

Examples

bash
htop
htop -u deploy
htop -t                    # tree view

kill

Send a signal to a process by PID.

devsysadmin

Syntax: kill [OPTIONS] PID...

Examples

bash
kill 1234                  # SIGTERM (15)
kill -9 1234               # SIGKILL — last resort
kill -HUP $(cat /var/run/nginx.pid)   # reload
kill -l                    # list signals

Pro Tip: Try SIGTERM and wait before -9 so apps can flush buffers.

pkill

Send signals to processes by name or pattern.

devsysadmin

Syntax: pkill [OPTIONS] PATTERN

Examples

bash
pkill -f 'gunicorn master'
pkill -u deploy old_worker
pkill -9 -f runaway_script.py

Pro Tip: Broad patterns can kill wrong PIDs — verify with pgrep -a first.

Warning: Double-check paths and targets. Mistakes can delete data or take down services.

bg

Resume a stopped job in the background.

dev

Syntax: bg [JOB_SPEC]

Examples

bash
# Ctrl+Z to stop, then:
bg
bg %2

fg

Bring a background/stopped job to foreground.

dev

Syntax: fg [JOB_SPEC]

Examples

bash
fg
fg %1

jobs

List active shell jobs.

dev

Syntax: jobs [OPTIONS]

Examples

bash
jobs -l
jobs -p                    # PIDs only

nohup

Run a command immune to hangups (SSH disconnect).

devsysadmin

Syntax: nohup COMMAND [ARGS...]

Examples

bash
nohup ./long_backup.sh &
nohup python train.py > train.log 2>&1 &

Pro Tip: Prefer tmux/screen or systemd for production long-running tasks.

screen

Terminal multiplexer (detachable sessions).

devinfra

Syntax: screen [OPTIONS] [CMD]

Examples

bash
screen -S deploy
screen -ls
screen -r deploy           # reattach
# Ctrl+a d to detach

tmux

Terminal multiplexer with panes and windows.

devinfra

Syntax: tmux [COMMAND]

Examples

bash
tmux new -s api
tmux ls
tmux attach -t api
tmux split-window -h

Pro Tip: Prefix Ctrl+b then c new window, % split vertical, d detach.

Disk & Storage

9 commands

df

Report filesystem disk space usage.

sysadmininfra

Syntax: df [OPTIONS] [FILE...]

Examples

bash
df -h
df -i /                   # inode usage
df -h /var /tmp

du

Estimate file/directory disk usage.

sysadmininfra

Syntax: du [OPTIONS] [FILE...]

Examples

bash
du -sh /var/log/* | sort -hr | head
du -x --max-depth=1 /data
du -sh .[!.]* * 2>/dev/null   # include dot dirs in cwd

lsblk

List block devices as a tree.

infra

Syntax: lsblk [OPTIONS]

Examples

bash
lsblk -f
lsblk -o NAME,SIZE,TYPE,MOUNTPOINT

mount

Attach a filesystem to the directory tree.

sysadmininfra

Syntax: mount [OPTIONS] DEVICE DIR

Examples

bash
mount /dev/sdb1 /mnt/backup
mount -o ro /dev/cdrom /media/cdrom
mount -a                 # all from /etc/fstab

umount

Detach a mounted filesystem.

sysadmininfra

Syntax: umount [OPTIONS] TARGET

Examples

bash
umount /mnt/backup
umount -l /mnt/stuck       # lazy unmount if busy
fuser -km /mnt/backup      # kill processes using mount (careful)

fdisk

Manipulate disk partition tables (MBR/GPT).

infra

Syntax: fdisk [OPTIONS] DEVICE

Examples

bash
fdisk -l
sudo fdisk /dev/sdb
fdisk -l /dev/nvme0n1

Pro Tip: Double-check device path (/dev/sdb vs /dev/sda). Prefer parted for GPT >2TB.

Warning: Double-check paths and targets. Mistakes can delete data or take down services.

parted

Partition editor with GPT support.

infra

Syntax: parted [DEVICE] [COMMAND]

Examples

bash
parted -l
parted /dev/sdb mklabel gpt
parted /dev/sdb mkpart primary ext4 0% 100%

Warning: Double-check paths and targets. Mistakes can delete data or take down services.

mkfs

Create a filesystem on a device (e.g. mkfs.ext4).

infra

Syntax: mkfs.TYPE [OPTIONS] DEVICE

Examples

bash
mkfs.ext4 /dev/sdb1
mkfs.xfs -f /dev/sdb1
mkfs.ext4 -L backup_vol /dev/sdb1

Pro Tip: Destructive — wipes data. Use wipefs -n first to verify device.

Warning: Double-check paths and targets. Mistakes can delete data or take down services.

blkid

Print block device attributes (UUID, TYPE).

infra

Syntax: blkid [OPTIONS] [DEVICE]

Examples

bash
blkid
blkid /dev/sdb1
grep $(blkid -s UUID -o value /dev/sdb1) /etc/fstab

Networking

14 commands

ping

Send ICMP echo requests (reachability, latency).

infradev

Syntax: ping [OPTIONS] HOST

Examples

bash
ping -c 4 8.8.8.8
ping -c 3 internal-api.local
ping6 2001:4860:4860::8888

curl

Transfer data from URLs (HTTP, APIs, downloads).

devinfra

Syntax: curl [OPTIONS] [URL...]

Examples

bash
curl -sS https://api.example.com/health | jq .
curl -o image.tar.gz https://releases.example.com/latest.tar.gz
curl -X POST -H 'Content-Type: application/json' -d '{"ok":true}' localhost:8080/hook
curl -vI https://example.com      # headers only, verbose

wget

Non-interactive network downloader.

infra

Syntax: wget [OPTIONS] [URL...]

Examples

bash
wget https://example.com/file.iso
wget -c https://example.com/big.zip   # resume
wget -r -np https://docs.example.com/  # mirror (careful)

netstat

Legacy network connections, routing, interfaces.

sysadmin

Syntax: netstat [OPTIONS]

Examples

bash
netstat -tlnp
netstat -rn
netstat -an | grep ESTABLISHED

Pro Tip: Prefer ss on modern Linux — faster and same info.

ss

Socket statistics (replacement for netstat).

infradev

Syntax: ss [OPTIONS]

Examples

bash
ss -tlnp
ss -tan state established '( dport = :443 or sport = :443 )'
ss -u -a
ss -s                    # summary

ip

Modern network config (iproute2): links, addresses, routes.

infra

Syntax: ip [OPTIONS] OBJECT COMMAND

Examples

bash
ip addr show
ip link set eth0 up
ip route show default
ip neigh show

ifconfig

Legacy interface configuration (deprecated on many distros).

infra

Syntax: ifconfig [INTERFACE]

Examples

bash
ifconfig
ifconfig eth0

Pro Tip: Use ip addr on Linux; ifconfig remains on macOS/BSD.

traceroute

Print route packets take to a host.

infra

Syntax: traceroute [OPTIONS] HOST

Examples

bash
traceroute example.com
traceroute -n 10.0.0.5     # no DNS
tracepath example.com      # alternative without raw sockets

nmap

Network scanner — ports, services, OS detection.

infra

Syntax: nmap [OPTIONS] TARGET

Examples

bash
nmap -sV localhost
nmap -p 1-1024 192.168.1.10
nmap -sn 192.168.1.0/24    # host discovery only

Pro Tip: Only scan networks you own or have written permission to test.

dig

DNS lookup utility.

infradev

Syntax: dig [@SERVER] NAME [TYPE]

Examples

bash
dig example.com A
dig +short api.example.com
dig @8.8.8.8 example.com MX
dig -x 93.184.216.34       # reverse DNS

nslookup

Interactive/non-interactive DNS queries.

infra

Syntax: nslookup [-OPTION] [NAME] [SERVER]

Examples

bash
nslookup example.com
nslookup -type=mx example.com

ssh

Secure shell — remote login and command execution.

devinfra

Syntax: ssh [OPTIONS] [USER@]HOST [COMMAND]

Examples

bash
ssh deploy@prod.example.com
ssh -i ~/.ssh/deploy_ed25519 -p 2222 bastion
ssh -L 5432:localhost:5432 db.internal   # local port forward
ssh -J bastion app.internal              # jump host

scp

Secure copy over SSH.

devinfra

Syntax: scp [OPTIONS] SOURCE TARGET

Examples

bash
scp build.tar.gz user@host:/opt/releases/
scp -r ./config/ user@host:~/app/
scp -3 hop:file1 hop:file2   # through two hosts

Pro Tip: rsync is better for large or incremental transfers.

rsync

Fast incremental file sync (local or remote).

infrasysadmin

Syntax: rsync [OPTIONS] SRC DEST

Examples

bash
rsync -avz --delete ./dist/ user@host:/var/www/app/
rsync -av /data/ /backup/data/
rsync -avz -e 'ssh -p 2222' file user@host:
rsync -av --dry-run src/ dest/   # preview

User Management

11 commands

useradd

Create a new user account.

sysadmin

Syntax: useradd [OPTIONS] LOGIN

Examples

bash
useradd -m -s /bin/bash deploy
useradd -r -s /usr/sbin/nologin nginx
useradd -G docker,sudo alice

usermod

Modify an existing user account.

sysadmin

Syntax: usermod [OPTIONS] LOGIN

Examples

bash
usermod -aG docker deploy
usermod -s /bin/bash serviceaccount
usermod -L locked_user         # lock password

userdel

Delete a user account.

sysadmin

Syntax: userdel [OPTIONS] LOGIN

Examples

bash
userdel oldcontractor
userdel -r tempuser            # remove home dir too

passwd

Change user password.

sysadmin

Syntax: passwd [OPTIONS] [USER]

Examples

bash
passwd
sudo passwd deploy
passwd -l account              # lock

groups

Show group memberships for a user.

sysadmin

Syntax: groups [USER]

Examples

bash
groups
groups deploy

id

Print UID, GID, and groups.

devsysadmin

Syntax: id [OPTIONS] [USER]

Examples

bash
id
id deploy
id -u -n                   # username only

who

Show who is logged in.

sysadmin

Syntax: who [OPTIONS]

Examples

bash
who
who -a
w                          # who + load + command

whoami

Print effective username.

dev

Syntax: whoami [OPTIONS]

Examples

bash
whoami
sudo whoami                # root when sudo works

su

Switch user (start a shell as another user).

sysadmin

Syntax: su [OPTIONS] [-] [USER]

Examples

bash
su -
su - postgres
su -s /bin/bash serviceuser

Pro Tip: Prefer sudo for audit trails instead of shared root password.

sudo

Execute command as another user (usually root).

devsysadmin

Syntax: sudo [OPTIONS] COMMAND

Examples

bash
sudo systemctl restart nginx
sudo -u deploy -H bash -l
sudo -l                    # list allowed commands
sudo visudo                # edit sudoers safely

visudo

Edit /etc/sudoers with syntax check.

sysadmin

Syntax: visudo [OPTIONS]

Examples

bash
sudo visudo
sudo visudo -f /etc/sudoers.d/deploy

Pro Tip: Broken sudoers can lock you out of root — always use visudo, never vim sudoers directly.

System Info & Monitoring

9 commands

uname

Print kernel and machine information.

devinfra

Syntax: uname [OPTIONS]

Examples

bash
uname -a
uname -r                   # kernel release
uname -m                   # x86_64, aarch64

hostname

Show or set the system hostname.

sysadmin

Syntax: hostname [OPTIONS] [NAME]

Examples

bash
hostname
hostname -f
hostnamectl set-hostname app-prod-01

uptime

How long the system has been running; load averages.

sysadmininfra

Syntax: uptime [OPTIONS]

Examples

bash
uptime
uptime -p                  # pretty duration

free

Display memory and swap usage.

infrasysadmin

Syntax: free [OPTIONS]

Examples

bash
free -h
free -h -s 5               # every 5 seconds
free -b | awk '/Mem:/ {print $7}'

Pro Tip: available column matters more than free on Linux — includes reclaimable cache.

vmstat

Virtual memory, processes, CPU, I/O stats.

infra

Syntax: vmstat [OPTIONS] [DELAY [COUNT]]

Examples

bash
vmstat 1 10
vmstat -w 1                # wide
vmstat -d                  # disk

iostat

CPU and disk I/O statistics (sysstat package).

infra

Syntax: iostat [OPTIONS] [INTERVAL [COUNT]]

Examples

bash
iostat -xz 1
iostat -cd 1 5

lscpu

CPU architecture information.

infra

Syntax: lscpu [OPTIONS]

Examples

bash
lscpu
lscpu -e=CPU,CORE,SOCKET,ONLINE

lshw

List hardware (detailed; may need root).

infra

Syntax: lshw [OPTIONS]

Examples

bash
sudo lshw -short
sudo lshw -class disk
sudo lshw -json

dmesg

Print kernel ring buffer messages.

infrasysadmin

Syntax: dmesg [OPTIONS]

Examples

bash
dmesg | tail -50
dmesg -T                   # human timestamps
dmesg -w                   # follow
dmesg | grep -i error

Package Management

6 commands

apt

High-level package manager (Debian/Ubuntu).

sysadmindev

Syntax: apt [OPTIONS] COMMAND

Examples

bash
sudo apt update
sudo apt install nginx
sudo apt upgrade -y
apt search ripgrep

apt-get

Lower-level APT tool (scripts/CI).

sysadmin

Syntax: apt-get [OPTIONS] COMMAND

Examples

bash
sudo apt-get update
sudo apt-get install -y build-essential
sudo apt-get remove --purge oldpkg

yum

Package manager (older RHEL/CentOS 7).

sysadmin

Syntax: yum [OPTIONS] COMMAND

Examples

bash
sudo yum install httpd
sudo yum update
yum search python3

Pro Tip: RHEL 8+ use dnf instead (yum is often a symlink).

dnf

Next-gen YUM (Fedora, RHEL 8+).

sysadmin

Syntax: dnf [OPTIONS] COMMAND

Examples

bash
sudo dnf install podman
sudo dnf upgrade
dnf repoquery -l nginx

rpm

Low-level RPM package queries and installs.

sysadmin

Syntax: rpm [OPTIONS]

Examples

bash
rpm -qa | grep nginx
rpm -ql nginx              # files in package
rpm -ivh package.rpm

dpkg

Low-level Debian package manager.

sysadmin

Syntax: dpkg [OPTIONS]

Examples

bash
dpkg -l | grep nginx
dpkg -L nginx
sudo dpkg -i package.deb
sudo dpkg-reconfigure package

Text Processing

9 commands

grep

Search text for patterns (regex).

devsysadmin

Syntax: grep [OPTIONS] PATTERN [FILE...]

Examples

bash
grep -r 'ERROR' /var/log/app/
grep -E 'timeout|refused' access.log
journalctl -u api | grep -i fatal
zgrep pattern archived.log.gz

sed

Stream editor — transform text.

devsysadmin

Syntax: sed [OPTIONS] 'SCRIPT' [FILE...]

Examples

bash
sed -i.bak 's/debug/info/' config.yaml
sed -n '10,20p' file.txt
grep old file | sed 's/old/new/g'
sed '/^#/d' .env > .env.clean

awk

Pattern scanning and column processing language.

devinfra

Syntax: awk [OPTIONS] 'PROGRAM' [FILE...]

Examples

bash
awk '{print $1, $NF}' access.log
awk -F: '$3 >= 1000 {print $1}' /etc/passwd
awk '/error/{c++} END{print c}' app.log
ps aux | awk '$3 > 50.0 {print $2, $11}'

cut

Extract columns from lines.

dev

Syntax: cut [OPTIONS] [FILE...]

Examples

bash
cut -d: -f1 /etc/passwd
cut -c1-8 file.txt
df -h | cut -d' ' -f1

sort

Sort lines of text.

dev

Syntax: sort [OPTIONS] [FILE...]

Examples

bash
sort -t, -k2 -n data.csv
sort -u names.txt
sort -h sizes.txt            # human numeric

uniq

Report or omit duplicate lines (requires sorted input).

dev

Syntax: uniq [OPTIONS] [INPUT [OUTPUT]]

Examples

bash
sort access.log | uniq -c | sort -rn | head
uniq -d duplicates.txt

tr

Translate or delete characters.

dev

Syntax: tr [OPTIONS] SET1 [SET2]

Examples

bash
tr '[:upper:]' '[:lower:]' < FILE
tr -d '\r' < windows.txt > unix.txt
cat ids | tr '\n' ','

xargs

Build and execute commands from stdin.

devsysadmin

Syntax: xargs [OPTIONS] [COMMAND]

Examples

bash
find . -name '*.tmp' -print0 | xargs -0 rm
cat hosts.txt | xargs -I{} ping -c1 {}
printf '%s\0' a b | xargs -0 echo

Pro Tip: Use -print0 and xargs -0 to handle filenames with spaces.

tee

Read stdin and write to stdout and files.

dev

Syntax: tee [OPTIONS] [FILE...]

Examples

bash
deploy.sh 2>&1 | tee deploy.log
echo 1 | sudo tee /proc/sys/net/ipv4/ip_forward
make test | tee results.txt

Archiving & Compression

6 commands

tar

Archive files (tarball); often combined with gzip/xz.

devsysadmininfra

Syntax: tar [OPTIONS] [FILE...]

Examples

bash
tar -czvf backup.tar.gz /data/app
tar -xzvf release.tar.gz
tar -tf archive.tar | head
tar -czf - ./app | ssh host 'tar -xzf - -C /opt'

Pro Tip: Modern tar: -c create -x extract -z gzip -v verbose -f file. Don't create archives of / without care.

gzip

Compress files with gzip (.gz).

dev

Syntax: gzip [OPTIONS] [FILE...]

Examples

bash
gzip large.log
gzip -9 -k file.txt          # keep original
gzip -d file.gz              # decompress

gunzip

Decompress gzip files (same as gzip -d).

dev

Syntax: gunzip [OPTIONS] [FILE...]

Examples

bash
gunzip access.log.gz
zcat access.log.gz | head

zip

Create ZIP archives.

dev

Syntax: zip [OPTIONS] ARCHIVE FILE...

Examples

bash
zip -r project.zip src/
zip -9 release.zip dist/*

unzip

Extract ZIP archives.

dev

Syntax: unzip [OPTIONS] ARCHIVE

Examples

bash
unzip -l archive.zip
unzip archive.zip -d ./out

bzip2

Compress with bzip2 (.bz2) — smaller, slower than gzip.

dev

Syntax: bzip2 [OPTIONS] [FILE...]

Examples

bash
bzip2 kernel.log
bzip2 -d file.bz2
tar -cjvf archive.tbz2 dir/

Shell & Scripting

9 commands

echo

Print a line of text.

dev

Syntax: echo [OPTIONS] [STRING...]

Examples

bash
echo $PATH
echo 'deb [arch=amd64] https://...' | sudo tee /etc/apt/sources.list.d/extra.list
echo -n 'no newline'

export

Mark shell variables for child processes.

dev

Syntax: export NAME[=VALUE]...

Examples

bash
export NODE_ENV=production
export PATH=$HOME/bin:$PATH
export -p | grep AWS

env

Run a command in a modified environment.

dev

Syntax: env [OPTIONS] [NAME=VALUE...] [COMMAND]

Examples

bash
env | sort
env -i HOME=$HOME PATH=$PATH bash --noprofile
env PYTHONPATH=./src python app.py

alias

Define command shortcuts in the shell.

dev

Syntax: alias NAME='VALUE'

Examples

bash
alias ll='ls -la'
alias k='kubectl'
unalias ll

Pro Tip: Put aliases in ~/.bashrc; they don't apply in non-interactive scripts.

source

Execute commands from a file in the current shell.

dev

Syntax: source FILE (or . FILE)

Examples

bash
source ~/.bashrc
source venv/bin/activate
. ./env.sh

history

Show shell command history.

dev

Syntax: history [OPTIONS]

Examples

bash
history | tail -20
history | grep ssh
!42                        # rerun command 42
Ctrl+r                     # reverse search

crontab

Schedule recurring jobs for the current user.

sysadmin

Syntax: crontab [OPTIONS]

Examples

bash
crontab -e
crontab -l
crontab -r                  # remove all (careful)
# 0 2 * * * /opt/backup.sh

Pro Tip: Use absolute paths and redirect output in cron — environment is minimal.

cron

Cron daemon — runs jobs from /etc/crontab and spool.

sysadmin

Syntax: N/A (service)

Examples

bash
systemctl status cron        # Debian
systemctl status crond       # RHEL
grep CRON /var/log/syslog
ls -la /etc/cron.d/

at

Schedule a one-time command.

sysadmin

Syntax: at [OPTIONS] TIME

Examples

bash
echo '/opt/report.sh' | at 02:00 tomorrow
atq
atrm 3

Logs & Debugging

5 commands

journalctl

Query systemd journal logs.

sysadmininfra

Syntax: journalctl [OPTIONS]

Examples

bash
journalctl -u nginx -f
journalctl -p err -b      # errors this boot
journalctl --since '1 hour ago'
journalctl -k             # kernel

syslog

Traditional syslog daemon and /var/log hierarchy (concept).

sysadmin

Syntax: N/A — see rsyslog/syslog-ng configs

Examples

bash
tail -f /var/log/syslog
tail -f /var/log/messages    # RHEL
grep sshd /var/log/auth.log
logger -t myapp 'deploy finished'

strace

Trace system calls and signals.

devinfra

Syntax: strace [OPTIONS] COMMAND

Examples

bash
strace -c ls /etc
strace -e openat,read,write -p 1234
strace -f -o trace.log ./app

Pro Tip: Adds overhead — don't leave attached in prod under load without cause.

lsof

List open files (sockets, dirs, devices).

sysadmininfra

Syntax: lsof [OPTIONS]

Examples

bash
lsof -i :8080
lsof -p 1234
lsof +L1 | grep deleted    # deleted but still open
lsof /var/lib/docker

ltrace

Trace library calls (libc).

dev

Syntax: ltrace [OPTIONS] COMMAND

Examples

bash
ltrace ls
ltrace -p 1234
ltrace -e malloc,free ./app