Linux Commands for DevOps Interviews: 6 Scenarios With Real Output
Disk full (and out of inodes), port in use, a systemd unit that will not start, high CPU or memory, errors in the logs and a safe Bash script: the commands and what their output tells you.
New13 min read

Linux commands for DevOps interviews are rarely asked as a list. The interviewer describes an incident instead, "the disk is full" or "the new release will not start", and wants to hear which commands you run, in what order, and what their output tells you.
This guide is for developers, many coming from Java and Spring Boot, who are moving into DevOps or preparing for a DevOps or cloud interview. It walks through six scenarios with the commands interviewers expect and the real output they produced. The runs used ubuntu:24.04 containers (Ubuntu 24.04.5 LTS, GNU bash 5.2.21, systemd 255) on Docker Desktop, plus one JVM check in a Temurin 25 image, all made for our Linux interview guide. Where a container behaves differently from a real server, the post says so.
In this guide
- How to answer a Linux scenario question
- Scenario 1: the disk is full
- Scenario 2: the port is already in use
- Scenario 3: the service will not start
- Scenario 4: high CPU or memory
- Scenario 5: find the error in the logs
- Scenario 6: write a safe Bash script
From the guide: this article draws on the troubleshooting scenarios section of Linux and Shell Scripting for DevOps Interviews, where every command and output was really run. Read the free 5-page sample on the guide page.
How to answer a Linux scenario question
Use the same shape every time: confirm the symptom, narrow it to one file system, port, unit or process, find the cause, fix the cause rather than the symptom, then say how you would prevent it. The first commands for each symptom:
- Disk full:
df -h, thendf -i. - Port in use:
ss -ltnpas root. - Service will not start:
systemctl status, thenjournalctl -u. - Slow server:
nproc,cat /proc/loadavg,vmstat 1. - Process vanished:
dmesg -Torjournalctl -k. - Error in the logs:
journalctl -g,grep -A,sort | uniq -c.
Scenario 1: the disk is full
The service logs No space left on device. In the guide's run, a 20 MB tmpfs at /data stands in for a server's /var, and a background process keeps its log open, like a JVM with a file appender, while it writes a retry error in a loop.
Find what filled it, then free it
df -h confirms which file system is full (see the df(1) man page). du -xh -d 2 /data | sort -h walks down from the mount point: -x stays on that file system, -d 2 limits the depth, and sort -h sorts human-readable sizes.
Then comes the classic mistake: rm on the log. The space stays in use, because a deleted file is only freed when the last process closes it. lsof +L1 shows such files: it selects open files that have been unlinked (fewer than 1 link left), and prints them with (deleted), the process and the descriptor (3w: descriptor 3, open for writing). Emptying the file through /proc/<pid>/fd/3 gives the space back and the service keeps running.
When df shows free space: inodes
An inode is the record that holds a file's metadata, and each file uses one. On ext4 the total is set when the file system is created, so a directory with millions of tiny files can exhaust them while plenty of blocks remain. The run limited the tmpfs to 1000 inodes: creating session files failed at sess_992 with the same error, while df -h showed 8.2M free.
$ df -h /data
Filesystem Size Used Avail Use% Mounted on
tmpfs 20M 20M 0 100% /data
$ du -xh -d 2 /data | sort -h
8.0M /data/releases
12M /data/log
12M /data/log/orders
20M /data
$ rm /data/log/orders/orders.log; df -h /data
Filesystem Size Used Avail Use% Mounted on
tmpfs 20M 20M 0 100% /data
$ lsof -nP +L1
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NLINK NODE NAME
sleep 14 root 3w REG 0,175 12582912 0 7 /data/log/orders/orders.log (deleted)
$ : > /proc/$(pgrep -x sleep)/fd/3; df -h /data
Filesystem Size Used Avail Use% Mounted on
tmpfs 20M 8.0M 12M 40% /data
$ df -h /data; df -i /data
Filesystem Size Used Avail Use% Mounted on
tmpfs 20M 12M 8.2M 60% /data
Filesystem Inodes IUsed IFree IUse% Mounted on
tmpfs 1000 1000 0 100% /datadu --inodes -xs /data/* | sort -rn counts files instead of bytes and pointed at /data/spool with 993. Deleting the session files brought IUse% back to 1 percent.
For prevention, truncate live logs instead of deleting them, rotate with logrotate, and alert at around 80 percent. Container note: lsof and /proc only see processes in the same PID namespace.
Scenario 2: the port is already in use
In the guide's run, an old instance started by hand by user olddeploy still held port 8080, and a small Python server standing in for the service failed with [Errno 98] Address already in use. Java reports it as java.net.BindException: Address already in use (checked with Temurin 25), and Spring Boot prints "Web server failed to start. Port 8080 was already in use."
ss -ltnp 'sport = :8080' lists listening (-l) TCP (-t) sockets with numeric ports (-n) and their processes (-p), see the ss(8) man page. Run it as root: as user nobody the process column stayed empty, as root it showed users:(("python3",pid=21,fd=3)). In a container, root also needs the SYS_PTRACE capability for that, which the run added.
Check the process before you stop it. ps -o pid,user,etime,cmd -p 21 showed the owner (olddepl+, cut by ps) and the elapsed time: weeks means a forgotten manual start, seconds a restart loop. fuser -k -TERM 8080/tcp sent it SIGTERM (without -TERM, fuser -k sends SIGKILL; see the fuser(1) man page), and the new instance logged orders: listening on 8080.
- Stop an old instance through whatever started it. A blind
kill -9on a unit withRestart=alwaysjust gets it restarted. - Make deploys wait for the old process to exit;
systemctl restartdoes that for a unit.
Scenario 3: the service will not start
A plain container has no systemd, so the guide ran this in a privileged Ubuntu 24.04 container booted with /sbin/init (systemd 255). The unit has User=orders, EnvironmentFile=-/etc/orders/orders.env and Restart=on-failure; its start script refuses to run without DB_URL, then starts a Python HTTP server in place of the Java process. The run breaks it three ways.
$ systemctl start orders; sleep 2; systemctl status orders --no-pager -n 0
● orders.service - Orders service
Loaded: loaded (/etc/systemd/system/orders.service; disabled; preset: enabled)
Active: activating (auto-restart) (Result: exit-code) since Wed 2026-11-25 16:49:20 UTC; 958ms ago
Process: 142 ExecStart=/opt/orders/bin/start.sh (code=exited, status=217/USER)
Main PID: 142 (code=exited, status=217/USER)
[exit code 3]
$ systemctl reset-failed orders; systemctl restart orders; sleep 2; journalctl -u orders -n 3 -o cat --no-pager; ls -l /opt/orders/bin/start.sh
Started orders.service - Orders service.
orders.service: Main process exited, code=exited, status=203/EXEC
orders.service: Failed with result 'exit-code'.
-rw-r--r-- 1 root root 219 Nov 25 16:49 /opt/orders/bin/start.sh
$ systemctl reset-failed orders; systemctl restart orders; sleep 10; systemctl is-active orders; journalctl -u orders -o cat --no-pager | grep -E "DB_URL|too quickly" | tail -n 2
failed
orders: DB_URL is not set, refusing to start
orders.service: Start request repeated too quickly.217/USER: theUser=does not exist. Create the system user.203/EXEC: theExecStartprogram could not be executed: missing, no execute bit, a wrong interpreter line or anoexecmount. Herels -lshowed mode 644.- A plain exit code: the application quit. Its reason is in the journal, and after repeated failures systemd stops with "Start request repeated too quickly".
With the environment file in place the unit became active, running as orders. Also mention systemctl daemon-reload after editing a unit and systemctl reset-failed to clear the start limit. The trap: reading only the last lines of systemctl status, which in a restart loop are systemd's own messages.
Scenario 4: high CPU or memory
Slow server: CPU or IO?
On Linux the load average counts running processes and processes in uninterruptible sleep (state D, usually waiting for disk). Compare it with nproc, then let vmstat 1 show where the time goes. The guide ran stress-ng in a container on the 8-CPU Docker Desktop VM: first 8 CPU workers, then 4 direct-IO writers. Below, ... marks cut lines, among them the first vmstat line, which is the average since boot.
$ nproc; cat /proc/loadavg
8
4.03 1.40 1.34 9/315 22
$ vmstat 1 3
procs -----------memory---------- ---swap-- -----io---- -system-- -------cpu-------
r b swpd free buff cache si so bi bo in cs us sy id wa st gu
...
8 0 0 8791912 48596 571184 0 0 0 0 5 436 100 0 0 0 0 0
...
$ cat /proc/loadavg
4.58 2.00 1.55 2/312 33
$ vmstat 1 3
...
0 4 0 8811404 49336 573840 0 0 0 162880 2622 5682 7 3 43 47 0 0
...
$ ps -eo state,pid,comm | awk '$1 == "D"'
D 29 stress-ng-hdd
D 30 stress-ng-hdd
D 31 stress-ng-hdd
D 32 stress-ng-hdd- CPU-bound:
us100,id0, 8 runnable processes inr. - IO-bound:
wa(IO wait) 47,id43, 4 blocked processes inb, all in stateD.
In a container, /proc/loadavg, nproc and vmstat show the whole VM, not the container. The guide names the next steps without showing their output here: for a Java process with high CPU, top -H -p <pid> and a thread dump; for IO, iostat -x 1 per device.
The Java process disappeared: the OOM killer
No stack trace and no hs_err file point at the kernel's OOM killer, which sends SIGKILL (exit code 137). The guide limited a container to 256 MB without swap: a Python process allocating in 25 MB steps printed allocated 225 MB, then died with exit code: 137. The kernel log, read from the Docker VM, said Memory cgroup out of memory: Killed process 44205 (python3); a whole machine running out says Out of memory. The VM uses cgroup v1; on a cgroup v2 host the limit file is memory.max.
The kernel counts RSS (resident memory), not just the heap: a Temurin 25 JVM with -Xmx128m holding 64 MB of arrays already had an RSS of 107,880 kB. Raising -Xmx after a kernel OOM kill makes the next one likelier. Size the heap so the whole process fits, and use OOMScoreAdjust= to choose the victim.
Scenario 5: find the error in the logs
For a systemd service, filter the journal: -u for the unit, -p warning for priority, --since for time, -g for a regular expression on the message (see the journalctl(1) man page). In the guide's systemd container, -p warning missed a java.lang.IllegalStateException line because systemd stores unprefixed stderr lines as info, while -g 'Exception|timeout' found it. A JVM adds no priority prefixes, so filter Java logs by content.
For log files, grep -A 4 prints four lines after a match, enough to see the exception under an ERROR line. Then count: awk cuts a column, sort | uniq -c counts each value (sort first, because uniq only compares adjacent lines). These ran on a Spring Boot style app.log and a 300-request nginx-style access.log:
$ grep -A 4 'Order 1044 failed' app.log
2026-11-25T10:00:03.789Z ERROR 4211 --- [orders] [nio-8080-exec-4] c.acme.orders.OrderService : Order 1044 failed
java.lang.IllegalStateException: Payment gateway timeout after 5000 ms
at com.acme.orders.PaymentClient.charge(PaymentClient.java:57)
at com.acme.orders.OrderService.place(OrderService.java:88)
at com.acme.orders.OrderController.create(OrderController.java:31)
$ awk '$9 >= 500 {print substr($4, 14, 5)}' access.log | sort | uniq -c
5 10:00
4 10:01
8 10:02
9 10:03
1 10:04The second command counts 5xx responses per minute. Two traps: grep -c counts lines, not matches, and grep -cw 500 counted 16 lines where only 15 had status 500, because one was a 500-byte response. For columns, awk '$9 == 500' is precise. If you then fix a config with sed -i, verify with grep -q: sed exits 0 even when nothing matched.
Scenario 6: write a safe Bash script
set -euo pipefail
The guide's test script has three silent failures. Without options it ended with pipeline status: 0 and script finished. Each option catches one:
-eexits when a command fails: it stopped after a failingcp.-umakes unset variables an error:steps.sh: line 4: TARGET_DIR: unbound variable.-o pipefailfails a pipeline when any part fails:grepon a missing file piped intosortnow gave status 2, not 0.
Side effect: under pipefail, yes | head -n 1 returned 141 (SIGPIPE). And -e is off inside if conditions and && or || lists, and local x=$(cmd) hides cmd's failure. The bash(1) man page lists every exception under the set builtin.
Clean up with trap
Create temp files with mktemp and register cleanup at once with an EXIT trap, which runs on a normal end, on exit and on set -e failures. Two signal traps route Ctrl-C and kill through exit too:
#!/bin/bash
# build a package in a private temp dir that is always removed
set -euo pipefail
workdir=$(mktemp -d)
cleanup() { rm -rf -- "$workdir"; echo "cleanup: removed $workdir" >&2; }
trap cleanup EXIT # runs on normal end, on exit, and on set -e failures
trap 'exit 130' INT # turn the signals into a normal exit,
trap 'exit 143' TERM # so the EXIT trap runs and the code stays meaningful
echo "working in $workdir"
echo payload > "$workdir/app.tar"
case ${1:-ok} in
fail) cp /no/such/file "$workdir/" ;;
wait) sleep 30 & wait $! ;; # wait, not plain sleep: lets the trap run at once
esac
echo "done"The guide ran it five ways. A normal end, a failing cp (exit 1), SIGINT (exit: 130) and SIGTERM (exit: 143) all printed the cleanup line. SIGKILL cannot be trapped: exit: 137, and /tmp/tmp.I2v2WyLIEK was left behind. The wait $! matters because bash runs a trap only after a foreground command finishes, while the wait builtin returns at once when a trapped signal arrives.
To report the failing line, add set -E and an ERR trap that prints $BASH_COMMAND and ${BASH_LINENO[0]}; the run printed ERROR: 'cp "/artifacts/$1" /tmp/' exited 1 at ./release.sh:11 (in fetch_artifact). Then run ShellCheck in CI on every *.sh file.
Go deeper
The guide, Linux and Shell Scripting for DevOps Interviews, has 100 questions in eight sections: files and permissions, processes and systemd, performance, networking, logs and journald, text processing, Bash scripting, and twelve troubleshooting scenarios, including broken DNS, SSH Permission denied (publickey), a failing cron job, leaking file descriptors and clock skew. Every output in it was really run in Ubuntu 24.04 containers.
The product page has a free 5-page sample. The DevOps and Cloud learning path puts it next to the Terraform, CI/CD and Kubernetes guides.
Related reading
- How to fix CrashLoopBackOff in Kubernetes
- GitHub Actions CI/CD for a Spring Boot app
- Spring Boot production checklist
FAQ
What Linux commands should I know for a DevOps interview?
Learn them by scenario: df, du and lsof for disk; ss and ps for ports; systemctl and journalctl for services; vmstat and dmesg for load and memory; grep and awk for logs; set -euo pipefail and trap for scripts.
How do I find which process is using a port in Linux?
Run sudo ss -ltnp 'sport = :8080'. It shows the listening socket with the process name and PID. Without root, the socket is still listed, but the process column stays empty for other users' processes.
Why is the disk still full after deleting a large file?
A process still has the file open, and the space is freed only when it closes it. lsof +L1 lists such files as (deleted). Truncate through /proc/<pid>/fd/<n> or restart that one service.
Why do I get No space left on device when df shows free space?
The file system has probably run out of inodes because of many small files. df -i shows IUse% at 100 percent, and du --inodes finds the directory with the most files.
What does set -euo pipefail do in Bash?
-e stops the script when a command fails, -u treats unset variables as errors, and -o pipefail fails a pipeline when any command in it fails. -e does not stop the script inside if conditions or && and || lists.





