Skip to content
DevOps AI ToolKit
Newsletter
Core Guide · Engineering Fundamentals

Linux Commands

A searchable Linux command reference for engineers who operate real systems — files, text, storage, processes, networking, services, permissions and troubleshooting — organized by task, with Ubuntu-first examples and the distribution differences that actually bite.

Last reviewed August 2026 Reference · Cheat sheet · 30 min read

Technically validated: Examples target modern GNU/Linux (Ubuntu 24.04 LTS, systemd). Notes call out where behavior differs on RHEL-family or with BSD/macOS userland.

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

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
# 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

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

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
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
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

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

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

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
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:

For a specific message, search the DevOps error library.

Production checklist

  • Quote every variable in scripts ("$path"), especially before rm, find -delete, dd.
  • df -h and df -i both — 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 recursive chmod/chown carefully.
  • lsblk before dd/mkfs. Confirm the device; there is no undo.
  • Prefer ip/ss/dig over the deprecated ifconfig/netstat/nslookup.
  • Scope strace/tcpdump on 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.

Continue learning

Related Core Guides that build on this one.

Written by James Joyner IV, Sr. Systems Software Engineer — for engineers who run what they build.

Last reviewed August 2026. Found an error or an out-of-date command? Tell us — accuracy is the point of a Core Guide.