Linux Interview Questions 101: A Comprehensive Guide to Mastering the Essentials


This guide is something new, taking a unique spin from my usual posts. Here, I dive deeper into essential Linux interview questions to help both beginners and seasoned pros navigate these core concepts with ease. I’ll explain each topic, offering both basic and advanced use cases, common pitfalls, best practices, and even troubleshooting tips where applicable.

Part 1: Core System Questions (1-12)

Q1: What is the boot process in Linux?

Answer:

The boot process starts when a system powers on and ends once the user can log in. The Linux boot process follows four main stages:

  1. BIOS/UEFI → Performs POST and locates bootloader
  2. Bootloader (GRUB) → Loads kernel into memory
  3. Kernel initialization → Mounts root filesystem, initializes hardware
  4. Init system (systemd) → Starts system services
Q2: How can you create a zero-size file in Linux?

Answer:

Three methods:

touch emptyfile.txt
truncate -s 0 emptyfile.txt
> newfile.txt
Q3: What are soft links and hard links in Linux? How do you create them?

Answer:

  • Soft Links (Symbolic):
ln -s /target/path /link/path
# Can span filesystems, breaks if original deleted
  • Hard Links:
ln /target/path /link/path
# Same inode, must be on same filesystem

Differences: Hard links can’t span filesystems and won’t break if the original file is deleted.
Use Cases: Soft links are great for shortcuts, while hard links are good for backups since they ensure data persistence.
Gotchas: Be cautious with soft links; if the target is removed, the link breaks.

Q4: What is the first line typically written in a shell script?

Answer:

#!/bin/bash # Shebang line - specifies interpreter

Without shebang: Must run explicitly with bash script.sh
With shebang: Can run with ./script.sh (after chmod +x)

Q5: How can you run a shell script in the background in Linux?

Answer:

./script.sh &          # Basic background execution
nohup ./script.sh &    # Persists after logout
screen -dm ./script.sh # Using screen session

Gotchas: Monitor background processes to avoid overloading resources.

Q6: What is a crontab in Linux?

Answer:

Schedules recurring jobs.
Crontab is a time-based job scheduler:

# Format: minute hour day_of_month month day_of_week command
# Example: Run daily at 3 AM
0 3 * * * /path/to/script.sh

# Edit crontab
crontab -e

# List current jobs
crontab -l

Gotchas: Ensure scripts have execute permissions and use full paths.
Troubleshooting: Check cron logs (/var/log/cron) if a job isn’t running.

Q7: How do you allow ports in Linux?

Answer:

# Using ufw
sudo ufw allow PORT
sudo ufw allow 80/tcp    # Allow HTTP
sudo ufw allow 22        # Allow SSH

# Using iptables
iptables -A INPUT -p tcp --dport PORT -j ACCEPT
iptables -A INPUT -p tcp --dport 80 -j ACCEPT # Allow HTTP

# Using firewall-cmd
firewall-cmd --add-port=PORT/PROTOCOL --permanent
firewall-cmd --add-port=80/tcp --permanent
firewall-cmd --reload # don't forget to reload

Use Case: Allow traffic for specific applications or services.
Best Practice: Only open necessary ports to limit vulnerabilities.

Q8: How do you troubleshoot a remote server experiencing issues?

Answer:

Sequential approach:

  • Check connectivity: ping server_ip
  • Monitor resources by SSHing into the server to analyze:
top         # CPU/Memory usage
df -h       # Disk space
netstat -an # Network connections
  • Check logs: tail -f /var/log/syslog
  • Review service status: systemctl status service_name

Advanced Use Case: For critical issues, use tools like tcpdump to inspect traffic.
Gotchas: Ensure SSH access and verify IP whitelisting.

Q9: What are the ping, telnet, curl, and wget commands in Linux?

Answer:

ping host.com      # Test network connectivity
telnet host 80     # Test specific port connectivity
curl url.com       # Transfer data from/to server
wget url.com       # Download files from web
Q10: How can you check the status of services in a Linux machine?

Answer:

systemctl status service_name  # Detailed status
service service_name status    # Basic status
ps aux | grep service_name     # Process check

Troubleshooting: For persistent issues, check system logs or journalctl.

Q11: How do you kill a process in Linux?

Answer:

kill PID           # Normal termination
kill -9 PID        # Force kill
killall process    # Kill by name
pkill process      # Pattern-based kill

Gotchas: Avoid using kill -9 unless necessary, as it skips cleanup.

Q12: What are the nice and renice commands in Linux?

Answer:

Purpose: Adjust process priority for CPU scheduling:

nice -n 10 command         # Start with lower priority
renice -n 10 -p PID       # Change running process priority
# Range: -20 (highest) to 19 (lowest)

Common Use Case: Prioritize critical processes on busy systems.
Gotchas: Use cautiously to avoid starving lower-priority processes.

I will continue with other questions later on.

In the next parts, we’ll cover questions focused on:

Questions 13-24: System Resources and File Management
Questions 25-36: Shell Scripting and Advanced Topics


Leave a Reply

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

Verified by MonsterInsights