Skip to content

Try “polymorphism”, “TCP handshake” or “git rebase”.

    Computer Basics / The Linux Command Line

    Interview Questions

    Real interview questions on The Linux Command Line, answered the way you would say them out loud.

    Extra: Interview prep4 min read

    Interview questions

    Given a web server access log, find the 10 IP addresses with the most requests.

    How I'd answer: "awk '{print $1}' access.log | sort | uniq -c | sort -rn | head -10. awk pulls out the first field, the IP. sort groups identical IPs together, because uniq only collapses adjacent duplicates. uniq -c counts each group. sort -rn sorts by the count numerically, biggest first, and head -10 keeps the top ten. It streams, so it works on files far larger than memory. If the log were huge and I needed it often, I'd send logs to a proper log system instead."

    Combines: Ch 5, 6.

    What does chmod 755 mean? What permissions should an SSH key or a .env file have?

    How I'd answer: "Each digit is one class — owner, group, others — and each is a sum of read 4, write 2, execute 1. So 755 is rwx for the owner and r-x for group and others: everyone can read and run it, only the owner can modify it — typical for scripts and directories. Secrets like SSH private keys and .env files should be 600, read-write for the owner only; SSH actually refuses to use a private key with looser permissions. And 777 is almost always a mistake."

    Combines: Ch 4.

    A production server's disk is full. Walk me through what you'd do.

    How I'd answer: "First confirm with df -h which filesystem is full. Then find what's using it with du -sh on the likely folders — usually /var/log, /tmp, or an app's data directory — sorted by size. The most common culprit is logs without rotation. I'd free space safely — compress or delete old rotated logs, not the live log a process is writing. If I delete a big file but df doesn't change, a process still has it open; lsof +L1 shows deleted-but-open files, and restarting that process releases the space. Afterwards I'd add log rotation and a disk-usage alert at, say, 80%, so it never surprises us again."

    Combines: Ch 6, 11, 12; Operating Systems Ch 10.

    How would you find which process is using port 8000, and stop it cleanly?

    How I'd answer: "lsof -i :8000 — or ss -tlnp | grep 8000 on Linux — shows the process name and PID. Then kill <pid>, which sends SIGTERM so the process can finish in-flight work and exit cleanly. I'd give it a few seconds and check it's gone. Only if it ignores SIGTERM would I use kill -9, since SIGKILL can't be caught and skips cleanup. If it's a systemd service, I'd use systemctl stop instead, otherwise systemd might just restart it."

    Combines: Ch 7, 11, 12.

    How do you securely connect to a database that's in a private subnet?

    How I'd answer: "The database shouldn't be reachable from the internet at all. One standard way is an SSH tunnel through a bastion host that is in the network: ssh -L 5433:<db-private-ip>:5432 bastion, then connect my client to localhost:5433. Traffic is encrypted to the bastion and the database only ever sees a connection from inside the VPC. The bastion itself only allows SSH with keys, from restricted IPs. Many teams now use managed options instead, like AWS Session Manager or GCP IAP, which avoid opening port 22 at all."

    Combines: Ch 10; Networking 1: Addresses and Routing Ch 11; Networking 2: TCP, UDP and Ports Ch 11.