On this page
The Linux command line is the DevOps engineer’s primary instrument — it’s where you diagnose a stuck host, tail a failing service, reclaim a full disk, and trace a network problem. This reference is organized by the task you’re doing, and every category has a searchable table so you can filter to the exact command in a second. The prose focuses on the commands with real nuance and the ones that can ruin your day if you get them wrong.
File management
File & directory commands
| Command | What it does | Risk |
|---|---|---|
ls -lah | List files: long format, all (incl. hidden), human-readable sizes. | Safe |
cp -a src dst | Copy, preserving mode/ownership/timestamps (archive). | Caution |
mv src dst | Move or rename (same filesystem = instant; across = copy+delete). | Caution |
rm -rf <path> | Recursively force-remove. No undo. No confirmation. | Destructive |
mkdir -p a/b/c | Create directories, including parents. | Safe |
touch file | Create an empty file or update its timestamp. | Safe |
find . -name '*.log' | Search a tree by name/size/time/type. | Safe |
find . -mtime +7 -delete | Find files older than 7 days and delete them. | Destructive |
locate <name> | Fast name search from a prebuilt index (updatedb). | Safe |
ln -s target link | Create a symbolic link. | Safe |
stat file | Show size, permissions, and timestamps. | Safe |
No commands match that filter.
find is the workhorse — it filters by name, age, size, and type, and can act on matches:
find /var/log -name '*.log' -size +100M # large logs
find . -type f -mtime +30 -print # files not modified in 30 days
find /tmp -type f -mtime +7 -delete # ...and delete them (dry-run first!)
Text processing
The Unix philosophy in practice: small tools piped together. grep finds, sed edits streams, awk processes columns, and the rest reshape text.
Text processing commands
| Command | What it does | Risk |
|---|---|---|
grep -rn 'pattern' . | Recursively search files, show line numbers. | Safe |
grep -i -E 'a|b' | Case-insensitive extended-regex search. | Safe |
sed 's/old/new/g' f | Stream-edit: substitute all matches (to stdout). | Safe |
sed -i 's/old/new/g' f | Edit the file IN PLACE. No backup unless -i.bak. | Caution |
awk '{print $2}' | Print the 2nd whitespace-delimited field of each line. | Safe |
awk -F, '$3>100' | CSV: print rows where column 3 exceeds 100. | Safe |
cut -d: -f1 /etc/passwd | Extract a delimited field. | Safe |
sort | uniq -c | Count occurrences of each unique line. | Safe |
tr -d '\r' | Delete characters (e.g. strip Windows CRs). | Safe |
wc -l file | Count lines. | Safe |
xargs -I{} cmd {} | Build commands from stdin (one per item). | Caution |
No commands match that filter.
# Top 10 client IPs in an access log
awk '{print $1}' access.log | sort | uniq -c | sort -rn | head
# Find-and-replace across a project (in place, with a .bak safety copy)
grep -rl 'oldName' src/ | xargs sed -i.bak 's/oldName/newName/g'
Filesystems and storage
The commands you reach for when a disk fills up or you’re provisioning storage.
Filesystem & storage commands
| Command | What it does | Risk |
|---|---|---|
df -h | Free/used space per mounted filesystem. | Safe |
df -i | Inode usage (a disk can be 'full' of inodes with free bytes). | Safe |
du -sh * | Size of each item in the current directory. | Safe |
du -h --max-depth=1 / | sort -h | Find what's eating a filesystem. | Safe |
lsblk | Tree of block devices and mount points. | Safe |
blkid | Show device UUIDs and filesystem types. | Safe |
mount /dev/sdb1 /mnt | Mount a filesystem. | Caution |
umount /mnt | Unmount a filesystem. | Caution |
fdisk -l | List disks and partition tables. | Safe |
mkfs.ext4 /dev/sdb1 | Create a filesystem — ERASES the partition. | Destructive |
dd if=... of=/dev/sdX | Raw block copy — wrong 'of' destroys a disk. | Destructive |
No commands match that filter.
When a host reports “disk full,” check three things in order:
df -h # which filesystem is full?
df -i # or is it inodes (millions of tiny files)?
du -h --max-depth=1 /var | sort -h # what in there is large?
Processes
Process commands
| Command | What it does | Risk |
|---|---|---|
ps aux | Snapshot of all processes with CPU/mem. | Safe |
ps -ef --forest | Process tree (parent/child relationships). | Safe |
top | Live process/resource monitor. | Safe |
htop | Friendlier interactive top (may need install). | Safe |
kill <pid> | Send SIGTERM (graceful stop) to a process. | Caution |
kill -9 <pid> | SIGKILL — force-kill, no cleanup. Last resort. | Destructive |
pkill -f 'pattern' | Kill processes matching a command pattern. | Destructive |
nice -n 10 cmd | Start a process with lower CPU priority. | Safe |
renice 10 -p <pid> | Change a running process's priority. | Caution |
nohup cmd & | Run detached from the terminal, survive logout. | Safe |
No commands match that filter.
Networking
The first-response toolkit for “is it a network problem?”
Networking commands
| Command | What it does | Risk |
|---|---|---|
ip a | Show interfaces and IP addresses (replaces ifconfig). | Safe |
ip r | Show the routing table. | Safe |
ss -tulpn | Listening TCP/UDP sockets + owning process (replaces netstat). | Safe |
ping -c 4 host | Test reachability + round-trip latency. | Safe |
traceroute host | Show the network path hop by hop. | Safe |
curl -I https://x | Fetch just the HTTP response headers. | Safe |
curl -sS -v https://x | Verbose request — TLS handshake, headers, timing. | Safe |
wget -O file url | Download a URL to a file. | Safe |
dig +short A host | Query DNS (concise). | Safe |
nslookup host | Query DNS (interactive-friendly). | Safe |
nc -zv host 443 | Test whether a TCP port is open. | Safe |
No commands match that filter.
ss -tulpn | grep :443 # what's listening on 443, and which PID?
nc -zv db.internal 5432 # can I even reach the DB port?
dig +short api.example.com # what does DNS resolve to right now?
curl -sS -o /dev/null -w '%{http_code} %{time_total}s\n' https://api.example.com/health
System services (systemd)
On modern Linux, services are systemd units. systemctl controls them; journalctl reads their logs.
systemd commands
| Command | What it does | Risk |
|---|---|---|
systemctl status <svc> | State, recent logs, PID of a service. | Safe |
systemctl start/stop <svc> | Start or stop a service now. | Caution |
systemctl restart <svc> | Restart a service. | Caution |
systemctl enable --now <svc> | Start now AND on boot. | Caution |
systemctl daemon-reload | Reload unit files after editing them. | Safe |
journalctl -u <svc> -f | Follow a service's logs live. | Safe |
journalctl -u <svc> --since '1h ago' | Logs for a time window. | Safe |
journalctl -p err -b | Error-priority messages since last boot. | Safe |
systemctl list-units --failed | Everything that failed. | Safe |
No commands match that filter.
systemctl status nginx # is it running? why did it stop?
journalctl -u nginx --since '10 min ago' # what did it log?
systemctl list-units --failed # what's broken on this host?
Permissions and ownership
Permission commands
| Command | What it does | Risk |
|---|---|---|
chmod 644 file | Set permissions numerically (rw-r--r--). | Caution |
chmod +x script.sh | Make a file executable. | Safe |
chmod -R 755 dir | Recursively set permissions. | Caution |
chown user:group file | Change owner and group. | Caution |
chown -R app:app /srv/app | Recursively change ownership. | Caution |
chgrp group file | Change group only. | Caution |
umask 022 | Set default permission mask for new files. | Safe |
No commands match that filter.
Numeric mode is owner|group|other, each a sum of read (4) + write (2) + execute (1): 644 = owner rw, group/other r; 755 = owner rwx, group/other rx.
Archives and compression
Archive commands
| Command | What it does | Risk |
|---|---|---|
tar czf a.tgz dir/ | Create a gzip-compressed tarball. | Safe |
tar xzf a.tgz | Extract a gzip tarball. | Caution |
tar tzf a.tgz | List a tarball's contents without extracting. | Safe |
gzip file / gunzip file.gz | Compress / decompress a single file. | Caution |
zip -r a.zip dir/ | Create a zip archive. | Safe |
unzip a.zip | Extract a zip archive. | Caution |
No commands match that filter.
The classic mnemonic: create, extract, test/list; add z for gzip, f for the filename. tar tzf (list) before tar xzf (extract) tells you where an archive will unpack — some tarballs extract into the current directory rather than a subfolder.
System information
System info commands
| Command | What it does | Risk |
|---|---|---|
uname -a | Kernel version and architecture. | Safe |
hostnamectl | Hostname, OS, kernel, virtualization. | Safe |
uptime | Load averages and how long the host has been up. | Safe |
free -h | Memory and swap usage. | Safe |
lscpu | CPU model, cores, architecture. | Safe |
lsmod | Loaded kernel modules. | Safe |
dmesg -T | tail | Kernel ring buffer (hardware/driver/OOM messages). | Safe |
No commands match that filter.
Troubleshooting
When something is wrong and you don’t yet know what, these open the black box.
Troubleshooting commands
| Command | What it does | Risk |
|---|---|---|
lsof -i :8080 | What process holds a given port. | Safe |
lsof -p <pid> | Files/sockets a process has open. | Safe |
lsof +D /path | What's keeping a filesystem/dir busy (can't unmount). | Safe |
strace -p <pid> | Trace a running process's system calls. | Caution |
tcpdump -i any port 443 | Capture packets for a port/interface. | Caution |
journalctl -p err -b | Boot-scoped error log. | Safe |
dmesg -T | grep -i oom | Was a process OOM-killed? | Safe |
No commands match that filter.
lsof -i :8080 # "address already in use" — who has the port?
dmesg -T | grep -i 'killed process' # did the OOM killer strike?
strace -f -e trace=openat -p 4242 # why can't the process find its config file?
Troubleshooting specific errors
Common Linux errors, each with a dedicated guide:
- cannot open shared object file — a missing
.so; resolve withldd/ldconfig. - cannot allocate memory — overcommit, ulimits, or genuine exhaustion.
- cannot assign requested address — binding/port/ephemeral-range issues.
- kernel panic: unable to mount root — boot/initramfs/root-device failures.
For a specific message, search the DevOps error library.
Production checklist
- Quote every variable in scripts (
"$path"), especially beforerm,find -delete,dd. df -handdf -iboth — inode exhaustion looks like “disk full” with free bytes.- SIGTERM before SIGKILL; give services a moment to shut down cleanly.
- Fix ownership, not
chmod 777. Scope recursivechmod/chowncarefully. lsblkbeforedd/mkfs. Confirm the device; there is no undo.- Prefer
ip/ss/digover the deprecatedifconfig/netstat/nslookup. - Scope
strace/tcpdumpon production; they cost performance and can capture secrets.
Frequently asked questions
What replaced ifconfig and netstat?
ip (addresses/routes) and ss (sockets). On modern kernels they’re faster and more accurate, and they’re what ships by default. ss -tulpn shows listening sockets with the owning process.
My disk says it’s full but du shows free space — why?
Two common causes: inode exhaustion (df -i — millions of tiny files) or a deleted-but-still-open file (a process holding a deleted log; lsof | grep deleted). Restart the holder or truncate the file.
How do I safely find-and-replace across many files?
grep -rl 'old' path | xargs sed -i.bak 's/old/new/g' — the .bak gives you a rollback, and grep -rl limits sed to files that actually match.
What’s the difference between kill and kill -9?
kill sends SIGTERM (catchable — the process cleans up and exits). kill -9 sends SIGKILL (uncatchable — instant stop, possible corruption). Try SIGTERM first.
Why does my sed -i fail on macOS?
BSD sed requires a backup-suffix argument: sed -i '' 's/.../.../'. Use sed -i.bak for a form that works on both GNU and BSD.
How do I see why a service won’t start?
systemctl status <svc> for the summary and journalctl -u <svc> --since '10 min ago' for the detail. systemctl list-units --failed shows everything currently broken.
Related resources
- Guide: Bash Scripting — turn these commands into safe, reusable automation.
- Academy: Ubuntu 26.04 AI Infrastructure and the Kali Linux path go deeper on Linux for DevOps and security.
- Error library: the 800+ DevOps error guides cover specific Linux failures step by step.
Continue learning
Related Core Guides that build on this one.
- Bash ScriptingWrite production-safe Bash: strict mode, error handling, traps, argument parsing and real automation templates you can drop into a pipeline.
- Git CommandsEvery Git command a DevOps engineer needs, organized by workflow — with copyable examples and clear risk labels for the destructive ones.
- Docker ComposeDocker Compose from services to production — networks, volumes, health checks, secrets, profiles and complete sample stacks you can run and adapt.
- DevOps ToolsA working engineer’s map of the DevOps toolchain — source control to platform engineering — with what each tool is for, its trade-offs, and how to choose.