10 Linux Shell Commands DevOps Engineers Must Master
Ten Linux shell commands DevOps engineers use in real incidents: grep, awk, sed, find, systemctl, journalctl, ss, curl, lsof and rsync, with examples.
The ten Linux shell commands DevOps engineers lean on most for troubleshooting and automation are grep, awk, sed, find, systemctl, journalctl, ss, curl, lsof and rsync. Together they cover searching logs, reshaping text, locating files, controlling services, reading the system journal, checking ports, testing HTTP endpoints, finding open files and syncing directories.
Instead of a long list with one line per command, this guide goes deep on ten, showing the options and combinations you use during real incidents and in pipeline scripts. For a broader quick reference, see top 20 Linux commands for DevOps engineers. Why Linux sits under almost every DevOps stack is covered in why Linux is the preferred OS for servers.
Key takeaways
- Most incidents start with the same questions: is the service running, what did it log, is it listening, can I reach it, what is filling the disk. These ten commands answer them.
- Learn pipelines, not just commands.
grep | awk | sort | uniq -canswers questions no single tool can. - On systemd distributions (RHEL, Ubuntu, Debian, Fedora) use
systemctlandjournalctlrather than old init scripts and/var/log/messagesalone. ssreplacesnetstat, which comes from the older net-tools package and is not installed by default on many current distributions.- Always dry-run destructive commands:
sedwithout-i,findwithout-delete,rsyncwith--dry-run.
The ten commands at a glance
| Command | Main job | Typical DevOps question it answers |
|---|---|---|
| grep | Search text by pattern | Which requests failed in this log? |
| awk | Process text by fields | Which client IPs or status codes appear most? |
| sed | Edit text streams | How do I change a config value in a script? |
| find | Locate files by attributes | What is filling the disk? Which files changed? |
| systemctl | Control systemd services | Is the service running, enabled, failed? |
| journalctl | Read the systemd journal | Why did the service crash at 02:14? |
| ss | Inspect sockets | Is anything listening on port 8080? |
| curl | Make HTTP and other requests | Is the endpoint up and where is the latency? |
| lsof | List open files | Which process holds this port or this deleted file? |
| rsync | Synchronise files | How do I copy a release directory efficiently? |
1. grep: find the lines that matter
grep prints lines matching a pattern. In DevOps work it is the first filter on any log or config file.
# Case-insensitive search with line numbers
grep -in "timeout" /var/log/nginx/error.log
# Extended regex: 5xx responses in an access log
grep -E '" 5[0-9]{2} ' /var/log/nginx/access.log
# Show 3 lines of context around each match
grep -C 3 "OutOfMemoryError" app.log
# Recursive search, only file names, skip a directory
grep -rl --exclude-dir=.git "DB_HOST" .
# Invert: hide noisy health checks
grep -v "/healthz" access.log | less
# Count matches
grep -c "ERROR" app.log
Useful habits: quote patterns so the shell does not expand them, use -F for fixed strings that contain regex characters, and use -o to print only the matched part. For compressed rotated logs, zgrep works on .gz files directly.
2. awk: treat text as columns
awk splits each line into fields ($1, $2 and so on, separated by whitespace by default) and runs a small program on them. It turns logs into answers.
# Top 10 client IPs in an Nginx access log (combined format: IP is field 1)
awk '{print $1}' access.log | sort | uniq -c | sort -rn | head
# Count requests per HTTP status code (field 9 in combined format)
awk '{count[$9]++} END {for (s in count) print s, count[s]}' access.log
# Sum a column: total bytes sent (field 10)
awk '{sum += $10} END {print sum/1024/1024 " MB"}' access.log
# Custom separator: list users and shells from /etc/passwd
awk -F: '{print $1, $7}' /etc/passwd
# Filter by value: processes using more than 5% memory
ps aux | awk 'NR == 1 || $4 > 5'
Field positions depend on your log format, so check one line first. For JSON logs, use jq instead of awk.
3. sed: edit text without opening an editor
sed applies edits to a stream or file. In automation it changes config values, strips lines and extracts sections.
# Preview a substitution (prints to stdout, file unchanged)
sed 's/^PermitRootLogin yes/PermitRootLogin no/' /etc/ssh/sshd_config
# Apply in place, keeping a backup with .bak suffix (GNU sed)
sed -i.bak 's/^PermitRootLogin yes/PermitRootLogin no/' /etc/ssh/sshd_config
# Delete comment and blank lines to see the effective config
sed -e '/^\s*#/d' -e '/^\s*$/d' /etc/ssh/sshd_config
# Print a line range
sed -n '120,160p' app.log
# Replace a placeholder in a template using a different delimiter
sed "s|__API_URL__|${API_URL}|g" config.tpl > config.json
GNU sed (on most Linux distributions) and BSD sed (on macOS) differ in how -i takes a backup suffix, which breaks scripts run on both. For structured files such as YAML or JSON, prefer yq or jq, or a configuration management tool, over regex edits. Our guide on searching and parsing text with grep, awk and sed has more examples.
4. find: locate files by name, size, age and owner
find walks a directory tree and filters by attributes. It is the standard tool when a disk fills up or you need to clean old artifacts.
# Files over 500 MB on the root filesystem only
find / -xdev -type f -size +500M -exec ls -lh {} + 2>/dev/null
# Log files not modified in 14 days (review first)
find /var/log/myapp -name "*.log" -mtime +14 -print
# Then delete them
find /var/log/myapp -name "*.log" -mtime +14 -delete
# Files changed in the last 30 minutes (useful after an incident)
find /etc -type f -mmin -30
# World-writable files, a common audit check
find / -xdev -type f -perm -0002 2>/dev/null
# Hand results to another command safely, even with spaces in names
find . -name "*.yaml" -print0 | xargs -0 grep -l "image: nginx"
Put -delete last; options are evaluated in order, so -delete before a filter deletes more than you meant. -xdev stops find crossing into other mounts such as /proc or network shares.
5. systemctl: control and inspect services
On systemd distributions, systemctl starts, stops and inspects services (units). It is often the first command when an alert says a service is down.
# Status, recent log lines and main PID
systemctl status nginx
# Start, stop, restart, or reload config without dropping connections
sudo systemctl restart nginx
sudo systemctl reload nginx
# Start now and on every boot
sudo systemctl enable --now nginx
# Which units have failed?
systemctl --failed
# Show the unit file and any drop-in overrides
systemctl cat nginx
# Override settings without editing the vendor unit file
sudo systemctl edit nginx
# Reload unit files after changing them
sudo systemctl daemon-reload
systemctl edit creates a drop-in under /etc/systemd/system/nginx.service.d/, which survives package upgrades. Use systemctl is-active and is-enabled in scripts; they return exit codes you can test.
6. journalctl: read what systemd and services logged
journalctl queries the systemd journal, which collects logs from services, the kernel and early boot. Filters make it far quicker than scrolling through text files.
# Logs for one unit, newest at the end, follow live
journalctl -u nginx -f
# A time window
journalctl -u myapp --since "2026-11-07 02:00" --until "2026-11-07 02:30"
# Relative time and priority: errors and worse in the last hour
journalctl -p err --since "1 hour ago"
# Current boot only; previous boot with -b -1
journalctl -b
journalctl -b -1 -p warning
# Kernel messages (OOM killer, disk errors)
journalctl -k | grep -i "out of memory"
# JSON output for scripts
journalctl -u myapp -o json --since today
# How much space is the journal using?
journalctl --disk-usage
Listing previous boots with journalctl --list-boots only works if the journal is persistent (stored under /var/log/journal). On Kubernetes nodes, journalctl -u kubelet is where node-level problems show up; see 10 hidden Kubernetes logs you should check.
7. ss: see what is listening and connected
ss (from the iproute2 package) shows sockets. It replaces netstat on current distributions.
# Listening TCP and UDP sockets with process names, numeric ports
sudo ss -tulpn
# Is anything listening on 8080?
sudo ss -ltnp 'sport = :8080'
# Established connections to a database port
ss -tn state established '( dport = :5432 )'
# Summary counts by state, handy during connection leaks
ss -s
"Connection refused" usually means nothing is listening (check ss -ltn), while a timeout points to a firewall, security group or routing issue. A service listening on 127.0.0.1 instead of 0.0.0.0 is a common cause of "works on the box, fails from outside".
8. curl: test endpoints and measure latency
curl sends requests and shows responses. It is the standard way to test APIs, health checks and TLS from a server or a pipeline.
# Headers only
curl -I https://example.com
# Verbose: DNS, TLS handshake, request and response headers
curl -v https://api.example.com/healthz
# Fail on HTTP errors (useful in CI), follow redirects, quiet output
curl -fsSL https://api.example.com/healthz
# Where is the time going?
curl -o /dev/null -s -w 'dns:%{time_namelookup} connect:%{time_connect} tls:%{time_appconnect} ttfb:%{time_starttransfer} total:%{time_total}\n' https://example.com
# POST JSON
curl -X POST -H "Content-Type: application/json" -d '{"name":"test"}' https://api.example.com/items
# Test a backend directly, bypassing DNS
curl --resolve app.example.com:443:10.0.1.15 https://app.example.com/
# Retry while a service starts
curl --retry 5 --retry-delay 2 --retry-connrefused -fsS http://localhost:8080/ready
Avoid passing tokens on the command line where they appear in shell history and process lists; read them from a file or environment variable with a header. Do not use -k (skip TLS verification) outside throwaway tests.
9. lsof: find which process holds a file or port
On Linux, sockets, pipes and devices are all files, so lsof answers a range of "who is using this?" questions.
# Which process is using port 8080?
sudo lsof -i :8080
# All network connections for one process
sudo lsof -i -a -p 1234
# Files open under a directory (why can't I unmount this?)
sudo lsof +D /mnt/data
# Deleted files still held open: disk full but du shows little
sudo lsof +L1
The last one solves a classic puzzle: df says the disk is full, du cannot find the space. A process is still writing to a log file that was deleted. Restarting or signalling the process (or truncating via /proc/PID/fd/N) frees the space. lsof may need installing on minimal images.
10. rsync: copy only what changed
rsync synchronises files locally or over SSH, transferring only differences. It is common in deployment scripts, backups and data migrations.
# Archive mode, compress, show progress, over SSH
rsync -avz --progress ./build/ deploy@web01:/var/www/app/
# Always preview a mirror with --delete first
rsync -avz --delete --dry-run ./build/ deploy@web01:/var/www/app/
# Exclude files
rsync -av --exclude '.git' --exclude 'node_modules' ./ /backup/project/
# Resume large transfers and keep partial files
rsync -av --partial --progress bigfile.tar.gz backup01:/data/
The trailing slash matters: build/ copies the contents of build, while build copies the directory itself into the target. --delete removes files on the target that are not in the source, so a wrong path can wipe a directory; that is why --dry-run comes first.
Putting them together: a short incident walkthrough
An alert says the API returns errors. A typical sequence on the host:
systemctl status api: the service is active but restarted a few minutes ago.journalctl -u api --since "15 min ago" -p warning: the log shows a database connection error.ss -tn '( dport = :5432 )': very few established connections to the database.curl -v telnet://db.internal:5432ornc -vz db.internal 5432: the connection times out, pointing at the network path rather than the app.- After the network fix,
grep -c " 5[0-9][0-9] " /var/log/nginx/access.logand anawkstatus count confirm errors have stopped.
Scripts that wrap these steps are easier to trust with good debugging habits; see best practices for debugging Bash scripts. For performance-specific tools such as vmstat, iostat and sar, read the best tools for troubleshooting Linux performance.
Practise on real systems
These commands, plus users, permissions, storage and systemd, are the core of our Linux administration training in Pune. If you are aiming for Red Hat certification, the RHCSA course covers the same tools on RHEL. Both run in the Kharadi classroom and live online across India.
Frequently asked questions
Which Linux commands should a DevOps beginner learn first?
Start with navigation and files (ls, cd, cp, mv, cat, less), then grep, find, systemctl, journalctl, ss and curl. Those cover most day-one troubleshooting. Add awk, sed, lsof and rsync as you start writing scripts.
What is the difference between grep, awk and sed?
grep selects lines that match a pattern. awk works on fields within lines and can calculate totals. sed edits text, such as replacing or deleting lines. They are often chained in one pipeline.
Is netstat still used?
netstat comes from the older net-tools package, which many current distributions no longer install by default. ss from iproute2 gives the same information and is the recommended replacement.
How do I see logs for a systemd service?
Run journalctl -u servicename. Add -f to follow live output, --since and --until for a time window, and -p err to show only errors.
Why does df show a full disk when du does not?
Usually a process still holds a deleted file open. Run lsof +L1 to find it, then restart the process or truncate the file through /proc to free the space.
Is it safe to use sed -i in production scripts?
It works, but test the expression without -i first and keep a backup suffix. For YAML or JSON files, use yq, jq or a configuration management tool, which understand the structure.
Do these commands work inside containers?
Many minimal images leave out tools like lsof, ss or even curl. Use kubectl debug or an ephemeral debug container with the tools installed instead of adding them to production images.
References
What's Your Reaction?
Like
0
Dislike
0
Love
0
Funny
0
Angry
0
Sad
0
Wow
0