Linux Interview Questions

Scenario Based Interview Questions

1. Troubleshooting Services:* 💡
• Scenario : Your application is running on an Apache web server, but the website is not accessible. What steps would you take to identify and resolve the issue?

2. Disk Space Management* :💡
• *Scenario* : You receive an alert that a production server is running low on disk space. How would you identify the files or directories consuming the most space and clean it up safely?

3. Process Monitoring and Optimization:* 💡
• *Scenario* : A server is experiencing high CPU usage, and the application performance is degraded. How would you identify the root cause and optimize the processes?

4. User Management and Permissions:* 💡
• *Scenario* : A user is unable to access a specific directory even though they belong to the correct group. How would you troubleshoot and resolve this permission issue?

5. Network Connectivity Issues:* 💡
• *Scenario* : Your server is unable to reach a specific external IP address. What steps would you take to diagnose and resolve this network connectivity issue?

6. File Recovery* :💡
• *Scenario* : An important configuration file has been accidentally deleted. How would you attempt to recover this file if there are no backups?

7. Automating Tasks with Shell Scripts:* 💡
• *Scenario* : You need to automate the deployment of an application. How would you use shell scripting to automate the process, including stopping services, copying files, and restarting services?

8. Log Analysis:* 💡
• *Scenario* : An application is intermittently failing. How would you use Linux command-line tools to analyze logs and identify the root cause of these failures?

9. Service Start-Up Failure:* 💡
• *Scenario* : A critical service fails to start after a server reboot. How would you diagnose and resolve the startup failure?

10. Kernel Tuning and Optimization* :💡
• *Scenario* : You need to optimize the server’s performance for a high-traffic application. How would you tune kernel parameters to improve system performance?

11. Managing Crontab Entries:* 💡
• *Scenario* : A scheduled cron job did not execute as expected. How would you troubleshoot this issue and ensure the job runs correctly in the future?

12. Handling Large File Transfers:* 💡
• *Scenario* : You need to transfer a large file securely from one server to another. What methods would you use to ensure the transfer is efficient and secure?

13. Deploying Updates with Zero Downtime* :💡
• *Scenario* : You need to deploy updates to an application without causing downtime. How would you achieve this on a Linux server?

14. Managing System Resources* :💡
• *Scenario* : The server’s memory usage is consistently high, affecting application performance. What steps would you take to identify the cause and manage system resources effectively?

Here’s a list of commonly asked shell scripting interview questions along with concise and accurate answers. These are categorized for beginners, intermediate, and advanced levels.

🔰 Beginner-Level Questions
1. What is a shell?
A shell is a command-line interpreter that provides a user interface for accessing services of an operating system. Examples include Bash, Zsh, Ksh, etc.
2. What is shell scripting?
Shell scripting is writing a series of commands in a file (script) to be executed by the shell automatically.
3. How do you create and run a shell script?
Create: nano script.sh or vi script.sh
Add shebang: #!/bin/bash
Make it executable: chmod +x script.sh
Run it: ./script.sh
4. What is the shebang (#!) in shell scripts?
It tells the system which interpreter to use. Example: #!/bin/bash uses Bash shell.
5. How do you declare a variable and use it?
name=”John”
echo “Hello, $name”

🧩 Intermediate-Level Questions

6. What are positional parameters?
They represent script arguments:
$0 → script name
$1, $2, … → first, second, etc., arguments
$@ → all arguments
$# → total number of arguments
7. How do you write an if condition in shell?
if [ “$age” -ge 18 ]; then
echo “Adult”
else
echo “Minor”
fi
8. How to write a loop in a shell script?
for i in {1..5}
do
echo “Count: $i”
done
9. How do you read input from a user?
read -p “Enter your name: ” name
echo “Hello, $name”
10. What is the difference between “$*” and “$@”?
“$*” treats all arguments as a single word.
“$@” treats each argument as a separate word.

🧠 Advanced-Level Questions

11. How do you handle errors in shell scripts?
Check exit status using $?
Use set -e to stop on errors
Use trap for cleanup
trap ‘echo “Error occurred”; exit 1’ ERR
12. How to redirect output and errors?
command > out.txt 2> err.txt # Separate
command &> all.txt # Combined (Bash)
13. What is the use of && and ||?
cmd1 && cmd2 → run cmd2 only if cmd1 succeeds
cmd1 || cmd2 → run cmd2 only if cmd1 fails
14. How to define and call a function in shell?
greet() {
echo “Hello, $1”
}
greet “World”
15. What is the difference between [ and [[ in Bash?
[[ is more powerful and allows string pattern matching
[ is POSIX-compliant and used in most shells
Would you like these questions as a downloadable PDF or want scenario-based examples too?

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top