INTERVIEW PREP
Interview questions
570 questions from real DevOps, SRE, platform engineering and MLOps interviews, with the answer an interviewer wants to hear. Try answering out loud first, then open the model answer.
Showing 1–15 of 224 questions
1.A disk is 100% full but du shows much less used. Why?MidLinux
A process still holds a deleted file open, so its blocks are not freed. Find it with lsof +L1 (or lsof | grep deleted), then restart that process or truncate the file through /proc/PID/fd. Also check inode exhaustion with df -i.
2.What happens when you run kill PID, and when would you use kill -9?MidLinux
kill sends SIGTERM, which a program can catch to shut down cleanly (flush data, close connections). SIGKILL (-9) cannot be caught; the kernel ends the process immediately, risking corrupt data. Use -9 only after SIGTERM has had time to work.
3.How does a systemd service restart automatically, and how do you see why it failed?MidLinux
Set Restart=on-failure (with RestartSec=) in the unit. Use systemctl status app for the latest state and exit code, and journalctl -u app -n 100 --no-pager (or -f to follow) for logs.
4.How do you find which files were changed in the last 24 hours?MidLinux
find / -xdev -type f -mtime -1 lists files modified less than one day ago on the root filesystem. Use -mmin -60 for the last hour, and -newer file to compare with a reference file.
5.What is an inode, and how can you run out of them?MidLinux
An inode stores a file's metadata (owner, permissions, where the data is) but not its name. Each filesystem has a fixed number. Millions of tiny files (cache, sessions, mail queue) can use them all while space is free; df -i shows it and No space left on device is the symptom.
6.How do you check which ports are open and what is listening on them?MidLinux
ss -tulpn lists TCP and UDP listening sockets with the owning process. From another host, nc -zv host 443 or nmap tests if the port is reachable, which also shows firewall problems.
7.What is the difference between sudo su, sudo -i and sudo command?MidLinux
sudo command runs one command as root and is logged, which is best practice. sudo -i starts a root login shell with root's environment. sudo su switches to root through su; it works but hides what you did afterwards from the sudo log.
8.How do you schedule a job, and why might a cron job work by hand but fail in cron?MidLinux
Use crontab -e or a systemd timer. Cron runs with a tiny environment: a short PATH, no shell profile, a different working directory and no terminal. Use full paths, set variables in the script, and send output to a log to see the error.
9.How do you make sure a temporary file is always cleaned up?MidBash Scripting
Create it with mktemp and register trap 'rm -f "$tmp"' EXIT. The trap runs however the script ends, including errors under set -e.
10.What is the difference between $@ and $*?MidBash Scripting
Quoted, "$@" expands to each argument as a separate word, preserving spaces inside arguments; "$*" joins all arguments into one string. Use "$@" to pass arguments on.
11.How do you read a file line by line safely?MidBash Scripting
while IFS= read -r line; do ...; done < file. IFS= keeps leading/trailing whitespace, -r keeps backslashes, and redirecting into the loop avoids a subshell so variables set inside survive.
12.How do you write a function that returns a value?MidBash Scripting
return only sets an exit code from 0 to 255. To return data, print it and capture it: get_ip() { hostname -I | awk '{print $1}'; } then ip=$(get_ip). Use local for variables inside functions.
13.How do you handle errors so the script stops and tells you where?MidBash Scripting
Use set -euo pipefail, plus trap 'echo "error on line $LINENO" >&2' ERR. Check commands whose failure is OK explicitly (cmd || true) and send error messages to stderr.
14.How do you loop over files whose names may have spaces?MidBash Scripting
Use a glob, not ls: for f in /data/*.csv; do process "$f"; done. With find, use find . -name '*.log' -print0 | while IFS= read -r -d '' f; do ...; done.
15.How do you parse options like -v and -f file in a script?MidBash Scripting
Use the getopts builtin: while getopts 'vf:' opt; do case $opt in v) verbose=1;; f) file=$OPTARG;; *) usage;; esac; done. Then shift $((OPTIND-1)) leaves the remaining arguments.