Linux and Bash course menu
Intermediate Linux and Shell Scripting Interview Questions
Intermediate Linux interview questions with answers: signals, systemd, cron, SSH keys, ports, sed and awk, environment variables, and Bash scripting.
On this page
- Processes and services
- 1. What is the difference between SIGTERM and SIGKILL?
- 2. What is a zombie process?
- 3. What is the difference between start and enable in systemctl?
- 4. How do you read a service's logs?
- 5. How do you keep a process running after logging out?
- 6. What is load average?
- Administration
- 7. Explain the five fields of a cron schedule.
- 8. Why might a script work by hand but fail in cron?
- 9. How does SSH key authentication work?
- 10. How do you find what is using a port?
- 11. The disk is full. What do you do?
- 12. What is the difference between a hard link and a soft link?
- 13. What is an inode?
- Text tools
- 14. Print the 10 most frequent IP addresses in a log.
- 15. How do you replace text in a file from the command line?
- 16. Why does uniq need sort?
- Scripting
- 17. What does #!/bin/bash do?
- 18. What is the difference between single and double quotes?
- 19. What are $?, $#, $@ and $0?
- 20. What does set -euo pipefail do?
- 21. What is the difference between source script.sh and ./script.sh?
- 22. How do you read a file line by line?
These questions check whether you can work on a real server and write reliable scripts.
Processes and services#
1. What is the difference between SIGTERM and SIGKILL?#
Show solution
SIGTERM (15) politely asks a process to stop, and it can clean up first. SIGKILL (9) ends it immediately, and it cannot be caught. Send SIGTERM first.
2. What is a zombie process?#
Show solution
A process that has finished, but whose parent has not read its exit status. It uses almost no resources, but it keeps its entry in the process table. It shows as Z in ps, and is cleared when the parent reads the status or exits.
3. What is the difference between start and enable in systemctl?#
Show solution
start runs a service now. enable makes it start at boot. enable --now does both.
4. How do you read a service's logs?#
Show solution
journalctl -u name, with -f to follow, -n 50 for the last lines, and --since for a time range. Many services also write to /var/log.
5. How do you keep a process running after logging out?#
Show solution
For quick jobs, use nohup command &, or tmux to keep a session alive. For real services, write a systemd unit, which also handles restarts and logs.
6. What is load average?#
Show solution
The average number of tasks running or waiting over 1, 5 and 15 minutes. Compare it with the number of CPU cores: a load of 4 on 4 cores means they are fully busy.
Administration#
7. Explain the five fields of a cron schedule.#
Show solution
Minute, hour, day of month, month, and day of week. */5 * * * * means every 5 minutes, and 30 2 * * 1 means 02:30 every Monday.
8. Why might a script work by hand but fail in cron?#
Show solution
cron has a minimal environment: a short PATH, no .bashrc, and a different current folder. Use full paths, set variables in the script, and log output with >> file 2>&1.
9. How does SSH key authentication work?#
Show solution
You hold a private key, and the server stores the public key in ~/.ssh/authorized_keys. The server sends a challenge, and your client proves that it has the private key by signing it, without sending the key.
10. How do you find what is using a port?#
Show solution
sudo ss -ltnp | grep :8080, or sudo lsof -i :8080.
11. The disk is full. What do you do?#
Show solution
Check with df -h, and find the biggest folders with du -h --max-depth=1 / | sort -hr. Common causes are logs, caches and Docker data. If du shows far less than df, use lsof +L1 to find deleted files that are still open. Also check inodes with df -i.
12. What is the difference between a hard link and a soft link?#
Show solution
A hard link is another name for the same inode, so the data remains until all names are removed. It cannot cross file systems or link to folders. A soft link stores a path, can cross file systems, and breaks if the target is removed.
13. What is an inode?#
Show solution
A record that stores a file's metadata (owner, permissions, size, data location), but not its name. Names are in directories. A disk can run out of inodes while it still has free space.
Text tools#
14. Print the 10 most frequent IP addresses in a log.#
Show solution
awk '{print $1}' access.log | sort | uniq -c | sort -nr | head -n 10
15. How do you replace text in a file from the command line?#
Show solution
sed -i 's/old/new/g' file. Use -i.bak to keep a backup.
16. Why does uniq need sort?#
Show solution
uniq compares only neighbouring lines, so duplicates must be next to each other.
Scripting#
17. What does #!/bin/bash do?#
Show solution
It is the shebang. It tells the system which interpreter should run the script.
18. What is the difference between single and double quotes?#
Show solution
Double quotes expand variables and command substitution. Single quotes keep the text exactly.
19. What are $?, $#, $@ and $0?#
Show solution
$? is the last exit code, $# is the number of arguments, "$@" is all the arguments as separate words, and $0 is the script's name.
20. What does set -euo pipefail do?#
Show solution
-e stops on a failed command, -u treats unset variables as errors, and -o pipefail makes a pipeline fail if any part of it fails.
21. What is the difference between source script.sh and ./script.sh?#
Show solution
./script.sh runs in a new process, so its variables disappear afterwards. source runs it in the current shell, so its variables and cd changes stay.
22. How do you read a file line by line?#
Show solution
while IFS= read -r line; do echo "$line"; done < file. Avoid for line in $(cat file), which splits on spaces.
Next: Advanced Questions.
Finished this lesson?