pwdUse this constantly to confirm where you are before running destructive commands.
Comprehensive Linux command reference covering navigation, files, text processing, permissions, processes, system information, networking, archives, services, storage, and troubleshooting.
Create, copy, move, inspect, and delete filesystem objects.
touch notes.txtAlso updates the modification time of an existing file.
mkdir -p app/logs/archive`-p` prevents errors if parent directories are missing.
cp -av src/ backup/src/`-a` preserves attributes and recursion, `-v` shows progress.
mv old-name.txt new-name.txtAlso used to move files between directories.
rm file.txtDouble-check with `ls` first when deleting important files.
rm -rf build/Dangerous. Verify the path carefully before running.
rmdir empty-dirFails if the directory contains files.
ln -s /opt/app/current app-currentSymlinks are useful for release switching, shared config, and path aliases.
ln original.txt twin.txtHard links only work on the same filesystem and usually not for directories.
stat /var/log/syslogExcellent for debugging permissions, timestamps, and file identity.
file archive.tar.gzUseful when an extension is misleading or absent.
du -sh *Useful for quickly finding which directories consume the most space.
df -hUse this before large downloads, backups, or container/image pulls.
basename /var/log/nginx/access.log .logHelpful in shell scripting and loops.
dirname /var/log/nginx/access.logCommon in scripts that need to construct sibling paths.
Read files, inspect content, and work with text streams.
cat /etc/os-releaseGood for small files and quick checks.
less /var/log/syslogSearch inside `less` with `/pattern` and quit with `q`.
head -n 20 app.logUseful for previewing large files quickly.
tail -n 50 app.logOften used on logs to inspect the latest events.
tail -f /var/log/nginx/access.logClassic log-following pattern while a service is running.
wc -l users.csvGreat for line counts in logs, CSVs, or batch outputs.
nl -ba config.ymlUseful when discussing exact lines in reviews or incidents.
cut -d: -f1 /etc/passwdA staple for colon-, comma-, or tab-delimited data.
paste names.txt emails.txtUseful for quick column composition without opening a spreadsheet.
column -t -s, data.csvHelpful for inspecting CSV-like data in the terminal.
sort -t, -k2,2n scores.csvCombine with `uniq`, `comm`, or `join` for powerful text workflows.
sort access.log | uniq -c | sort -nrRemember to sort first if you want global duplicate counts.
tr '[:lower:]' '[:upper:]' < input.txtAlso useful for squeezing repeated delimiters with `-s`.
make 2>&1 | tee build.logGreat for preserving command output while still seeing it live.
Search text, files, directories, and command history efficiently.
grep -n 'ERROR' app.log`-n` adds line numbers. Add `-i` for case-insensitive searches.
grep -RIn 'TODO' src/A standard codebase search when ripgrep is unavailable.
grep -v '^#' .env.exampleUseful for stripping comments or blank lines when combined with other filters.
grep -E 'warn|error|fatal' app.logEquivalent to historical `egrep`; `grep -E` is preferred.
grep -F 'user[id]' app.logUse when the pattern contains regex metacharacters you want treated literally.
rg 'connection refused' .Popular for source-code and repo searches due to speed and sane defaults.
find /var/log -type f -mtime -1Helpful for cleanup jobs and recent-activity investigations.
find / -type f -size +500M 2>/dev/nullUseful in disk pressure incidents.
find . -name '*.tmp' -print0 | xargs -0 rm -fEssential when combining `find` with bulk operations safely.
history | grep dockerA good way to recover a command you ran last week but forgot to save.
Manage modes, ownership, access, and identity.
ls -l /var/wwwThe first step in diagnosing file access problems.
chmod 640 secrets.envNumeric modes are concise and script-friendly.
chmod -R u=rwX,go=rX public/Prefer symbolic recursive modes for directories so execute is only set where appropriate.
chown deploy:www-data app.logCommon after copying files as root or changing deployment users.
chgrp www-data storage/Useful when a shared service account needs group access.
umask 027A stricter umask helps keep new files from being world-readable.
idQuickly confirms which groups a process or login shell belongs to.
whoamiHandy in `sudo` sessions and provisioning scripts.
getfacl shared/Useful when POSIX ACLs override or supplement traditional mode bits.
setfacl -m u:alice:rwx shared/Helpful when one extra user needs access without changing ownership.
sudo systemctl restart nginxKeep privilege escalation narrow and targeted.
sudoedit /etc/ssh/sshd_configSafer than running the editor as root directly.
Create users, manage groups, inspect sessions, and handle logins.
sudo useradd -m -s /bin/bash deploy`-m` creates the home directory and `-s` sets the login shell.
sudo usermod -aG docker aliceAlways include `-a` with `-G` to avoid overwriting existing supplementary groups.
sudo passwd deployAlso used to lock and unlock passwords on many systems.
sudo groupadd appteamUseful for shared file access patterns.
groups aliceUseful when access depends on group membership.
su - postgresClassic for service accounts that own app data or databases.
whoHelpful on shared servers and bastion hosts.
wA quick operations view of who is on the machine and what they are doing.
last -a | headUseful for forensic review and access audits.
sudo pkill -u olddeployUse carefully on multi-user systems.
Inspect, prioritize, signal, background, and schedule processes.
ps auxOne of the most common process-inspection commands.
ps -ef --forestHelpful for understanding supervisors, workers, and spawned shells.
topBuilt into most systems and good for quick diagnostics.
htopFriendlier than `top` if installed.
pgrep -af nginxGreat for scripts and quick service discovery.
kill -TERM 12345Prefer TERM before KILL so apps can shut down cleanly.
kill -KILL 12345Use only when a process ignores or cannot handle graceful signals.
pkill -f 'gunicorn: master'Convenient when you do not want to look up PIDs manually.
nice -n 10 tar -czf backup.tgz /srv/dataHigher nice values are lower priority.
sudo renice -n 5 -p 12345Useful when a process should yield more CPU to others.
jobs -lOnly applies to jobs started from the same shell session.
bg %1Useful after pressing Ctrl+Z on a long-running command.
fg %1Useful when you need to interact with the command again.
nohup ./long-task.sh > task.out 2>&1 &Useful on remote shells when a process should survive disconnects.
crontab -eClassic recurring scheduler for scripts, backups, and maintenance tasks.
crontab -lUseful before changing automation on a server.
echo 'systemctl restart worker' | at 02:00Useful for maintenance actions that should run once at a known time.
Inspect OS details, CPU, memory, uptime, devices, and kernel state.
uname -aCommon first step to see what OS and kernel you are on.
hostnamectlOn systemd systems this is richer than plain `hostname`.
cat /etc/os-releasePortable way to detect distro family in scripts or debugging.
uptimeUseful during incidents and after reboots.
free -hCommonly used alongside `top`, `ps`, and `vmstat`.
lscpuUseful for capacity planning and debugging architecture issues.
lsblk -fExcellent for storage troubleshooting and identifying filesystems.
sudo blkidOften used when preparing `/etc/fstab` entries.
mount | column -tUseful to inspect what is currently mounted and with which options.
sudo umount /mnt/dataAlways ensure no process is using the mount before unmounting.
dmesg -T | tail -n 50Great for device, disk, driver, and OOM-related debugging.
lsusbUseful for debugging peripherals, storage, serial, and dev boards.
lspci -nnUseful for graphics, NIC, NVMe, and virtualization inspection.
Inspect interfaces, routes, connections, DNS, and remote connectivity.
ip address showModern replacement for `ifconfig` on most Linux systems.
ip link showUse this to see whether interfaces are up, down, or renamed.
ip route showEssential when debugging egress paths and default gateways.
ss -tulpnModern replacement for `netstat -tulpn` on many systems.
ping -c 4 8.8.8.8Good first test for network reachability and latency.
traceroute example.comUseful for diagnosing where connectivity breaks across hops.
dig +short A example.comPreferred over older tools for precise DNS debugging.
nslookup example.comStill common, though `dig` is often more scriptable and explicit.
host 8.8.8.8Quick and minimal DNS utility.
curl -I https://example.comGreat for headers, health checks, APIs, and downloads.
wget https://example.com/file.tar.gzUseful for unattended downloads and mirroring.
ssh user@server.example.comA core Linux skill for administration and deployments.
scp app.tar.gz user@server:/tmp/Simple and widely available for secure file copy.
rsync -avz ./dist/ user@server:/var/www/app/A deployment and backup staple thanks to speed and repeatability.
nc -vz example.com 443Excellent for quick TCP connectivity tests.
nmap -sV example.comUse responsibly and only on systems you are authorized to scan.
sudo tcpdump -i any port 443Powerful for low-level debugging of connections, TLS, DNS, and service issues.
Create archives, compress files, and verify integrity.
tar -cvf backup.tar app/Classic archiving tool for backups and packaging.
tar -czvf backup.tar.gz app/Common format for source releases and backups.
tar -xzvf backup.tar.gzAdd `-C /target/path` to extract elsewhere.
gzip large.logSimple and widely supported compression format.
gunzip large.log.gzEquivalent to `gzip -d`.
zip -r release.zip dist/Convenient when sharing with systems that expect zip.
unzip release.zip -d release/Simple cross-platform archive extraction.
xz -T0 dump.sqlExcellent compression ratios, often used for large text dumps.
sha256sum release.tar.gzUseful for verifying downloads and release artifacts.
md5sum file.isoMostly used for legacy checks; prefer SHA-256 for stronger integrity assurance.
Edit text streams, transform columns, and script data extraction.
sed 's/localhost/db.internal/g' config.tplUseful for one-off substitutions in streams or pipelines.
sed -i.bak 's/debug=false/debug=true/' app.confCreate a backup suffix when editing important files.
sed -n '100,140p' big.logHelpful for extracting a specific section without opening an editor.
awk '{print $1, $5}' access.logGreat for quick field extraction and lightweight reporting.
awk '{sum += $3} END {print sum}' metrics.txtUseful for fast command-line summaries.
awk '$5 > 100 {print $0}' usage.txtUseful when conditions go beyond what `grep` handles cleanly.
jq '.' response.jsonA must-have when APIs or tools emit raw JSON.
jq -r '.items[].metadata.name' pods.jsonExcellent for combining API JSON with shell pipelines.
yq '.services.web.image' docker-compose.ymlUseful for Kubernetes, Compose, CI, and config files.
comm -3 <(sort old.txt) <(sort new.txt)Handy for diffing identifier lists and inventory files.
join -1 1 -2 1 users.txt emails.txtUseful when doing small-scale data joins in shell pipelines.
split -l 100000 huge.csv chunk_Helpful for batch imports or sharing giant files.
Manage services, units, boot targets, and logs on systemd hosts.
systemctl status nginxA first-stop diagnostic for any systemd-managed service.
sudo systemctl start nginxUse after install or when recovering a stopped service.
sudo systemctl stop nginxUse before maintenance or configuration changes when needed.
sudo systemctl restart nginxCommon after config changes or deployments.
sudo systemctl reload nginxPrefer reload when the service supports it and you want minimal disruption.
sudo systemctl enable nginxEnsures the service starts automatically after reboot.
sudo systemctl disable nginxUseful for deprecated or temporary services.
systemctl list-units --type=serviceUseful for discovering services and their current states.
journalctl -u nginx -n 100 --no-pagerA standard service-specific log query on systemd systems.
journalctl -fu nginxCombines `-f` follow mode with unit filtering.
journalctl -bUse `-b -1` to inspect the previous boot.
timedatectlImportant when debugging clock drift, certificates, or scheduled tasks.
sudo hostnamectl set-hostname app-prod-01Preferred over editing files manually on systemd systems.
Work with disks, partitions, filesystems, and logical volumes.
sudo fdisk -lClassic disk inventory command.
sudo parted /dev/sda printUseful for modern disks and scripted partition management.
sudo mkfs.ext4 /dev/sdb1Formatting destroys existing data; verify the target device carefully.
sudo fsck -f /dev/sdb1Run on unmounted filesystems when possible.
sudo mount /dev/sdb1 /mnt/dataEnsure the mountpoint exists first.
sudo swapon /swapfileUseful when adding or restoring swap.
sudo swapoff /swapfileEnsure the system has enough RAM before disabling swap.
sudo pvsStart here when inspecting LVM-backed systems.
sudo vgsUseful for capacity and free-extent checks.
sudo lvsUseful for seeing LV names, sizes, and attributes.
sudo lvextend -L +20G /dev/vg0/dataOften followed by filesystem growth with `resize2fs` or `xfs_growfs`.
sudo resize2fs /dev/vg0/dataCommon after extending an LV or block device.
Gather CPU, memory, IO, and process diagnostics during incidents.
vmstat 1 5A compact snapshot for system pressure and waiting behavior.
iostat -xz 1 5Useful for diagnosing disk saturation and queue depth.
sar -u 1 5Great when sysstat is installed and enabled for ongoing collection.
mpstat -P ALL 1 5Useful when one core is pegged but system average looks fine.
pidstat 1 5Helps connect system pressure to specific workloads.
lsof -i :8080Excellent for determining what process owns a port or file.
strace -p 12345Powerful for seeing what a stuck or failing process is trying to do.
time rsync -av src/ backup/Useful for baseline timing and quick performance comparison.
watch -n 2 'df -h && echo && free -h'Great for observing changing state without rerunning commands manually.
timeout 30s curl -I https://example.comUseful in scripts to avoid hanging forever.