Posted in

30+ Linux Interview Questions and Answers for All Experience Levels






30+ Linux Interview Questions and Answers for All Experience Levels

Whether you’re a fresher stepping into your first Linux role, an experienced administrator looking to advance your career, or someone preparing for a technical interview at companies like Google, Amazon, or Zoho, this comprehensive guide covers essential Linux interview questions spanning beginner to advanced levels. These questions reflect real-world scenarios and technical concepts you’ll encounter in Linux system administration roles.

Basic Linux Interview Questions (Fresher Level)

1. What is Linux and what are its main advantages?

Answer: Linux is an open-source operating system based on Unix. Its main advantages include:

  • Open-source nature—source code is freely available for modification and distribution
  • Cost-effective—no licensing fees required
  • Portability—runs on various hardware platforms
  • Security—robust security features and user privilege separation
  • Stability and reliability—can run for years without restart
  • Multi-user and multitasking capabilities—multiple users can work simultaneously

2. What is the difference between Unix and Linux?

Answer: While Linux is based on Unix principles, key differences include:

  • Unix is proprietary software, while Linux is open-source
  • Unix is more expensive, while Linux is free
  • Unix is used primarily in enterprises and servers, while Linux has broader adoption across desktops, servers, and embedded systems
  • Linux has a larger community support base
  • Unix systems are typically closed-source, making customization difficult

3. How do you check the Linux kernel and operating system version?

Answer: You can use several commands:

uname -a          # Displays all system information
uname -r          # Shows kernel release version
cat /etc/os-release  # Displays OS version details
lsb_release -a    # Shows Linux distribution information

4. How do you list all files including hidden files in a directory?

Answer: Use the ls command with the -a flag:

ls -a             # Lists all files including hidden ones (starting with .)
ls -la            # Lists all files with detailed information

5. What is the Unix/Linux command to remove a directory and its contents?

Answer: Use the rm command with recursive flag:

rm -r directory_name    # Removes directory and its contents
rm -rf directory_name   # Forces removal without prompting

6. Which command shows free and used memory in Linux?

Answer: Use the free command:

free              # Shows memory usage in kilobytes
free -h           # Shows memory usage in human-readable format (GB, MB)
free -m           # Shows memory in megabytes

The command displays total, used, and available memory. Free memory doesn’t truly exist on Linux because the OS uses available memory for caching and buffering to improve performance.

7. How do you search for a string in files of a directory recursively?

Answer: Use the grep command with recursive flag:

grep -r "search_term" /path/to/directory
grep -ri "search_term" /path/to/directory  # Case-insensitive search

8. What does CTRL+D do in Linux?

Answer: CTRL+D sends an EOF (End-Of-File) signal to the terminal. It’s commonly used to exit the current shell or terminate input when a program is waiting for input.

9. What does CTRL+Z do in Linux?

Answer: CTRL+Z suspends the current running process and returns you to the shell prompt. The process is paused in the background. You can resume it using the fg (foreground) command.

10. Explain the three load averages and what they indicate.

Answer: Load average represents the average number of processes running or waiting on the CPU. The three numbers show average load over:

  • First number: Last 1 minute
  • Second number: Last 5 minutes
  • Third number: Last 15 minutes

View load averages using:

uptime       # Shows load averages and system uptime
top          # Displays real-time system statistics including load average

Intermediate Linux Interview Questions (1-3 Years Experience)

11. How do you check system load and memory usage?

Answer: Several commands are available:

top              # Interactive view of processes and system resources
htop             # Enhanced version of top with better visualization
vmstat           # Virtual memory statistics
free -h          # Memory usage information
uptime           # System uptime and load averages

The top command is most commonly used as it provides comprehensive real-time system monitoring in a single interface.

12. How do you find and terminate a process in Linux?

Answer: First, locate the process:

ps aux | grep process_name   # Find specific process
ps -ef                        # List all running processes

Then terminate it:

kill PID                      # Graceful termination
kill -9 PID                   # Forceful termination (SIGKILL)

13. What is the umask command and how is it used?

Answer: The umask (user file creation mask) determines default permissions for newly created files and directories. It subtracts from the default permissions (666 for files, 777 for directories).

View current umask:

umask            # Displays current umask value

Set temporary umask:

umask 022        # Changes umask for current session

14. How do you permanently assign umask to a user?

Answer: Place the umask command in the appropriate shell profile file. The file depends on the user’s default shell:

  • For bash: ~/.bashrc or ~/.bash_profile
  • For zsh: ~/.zshrc
  • For sh: ~/.profile

Add this line to the profile file:

umask 022

This ensures the umask is applied whenever the user logs in.

15. What is the difference between systemctl disable and systemctl mask?

Answer: Both prevent a service from starting, but they differ:

  • systemctl disable: Removes the service from auto-start but it can still be manually started with systemctl start
  • systemctl mask: Creates a symbolic link to /dev/null, preventing both automatic and manual startup. It’s a stronger form of disabling

16. How do you redirect STDOUT and STDERR in bash?

Answer: Use redirection operators:

command > file           # Redirect STDOUT to file
command 2> file          # Redirect STDERR to file
command > file 2>&1      # Redirect both STDOUT and STDERR to file
command > /dev/null 2>&1 # Discard both outputs

17. What is in /etc/services and why is it important?

Answer: The /etc/services file contains mappings of well-known service names to their port numbers and protocol types (TCP/UDP). It allows applications and administrators to reference services by name rather than memorizing port numbers. For example, it maps “http” to port 80, “ssh” to port 22, and “smtp” to port 25.

18. What is LVM (Logical Volume Manager) and why would it be required?

Answer: LVM is a storage management technology that abstracts physical storage into logical volumes. Benefits include:

  • Ability to resize partitions without downtime
  • Flexible storage allocation across multiple physical disks
  • Snapshots for backup purposes
  • Dynamic addition of new storage
  • Better management of large storage systems

19. How would you increase the size of an LVM partition?

Answer: Follow these steps:

# 1. Extend the logical volume
lvextend -L +10G /dev/vg_name/lv_name

# 2. Resize the file system (for ext4)
resize2fs /dev/vg_name/lv_name

# 3. For XFS file system use:
xfs_growfs /dev/vg_name/lv_name

20. How would you reduce the size of an LVM partition?

Answer: This requires care to avoid data loss:

# 1. Unmount the file system
umount /mount_point

# 2. Check the file system
e2fsck -f /dev/vg_name/lv_name

# 3. Reduce the file system size
resize2fs /dev/vg_name/lv_name 5G

# 4. Reduce the logical volume
lvreduce -L 5G /dev/vg_name/lv_name

# 5. Remount the file system
mount /dev/vg_name/lv_name /mount_point

21. Where are SAR logs stored and how do you use them?

Answer: SAR (System Activity Report) logs are typically stored in /var/log/sa/ directory. Each file corresponds to a specific day (sa01, sa02, etc.). View SAR data:

sar              # Displays today's SAR data
sar -f /var/log/sa/sa15  # Displays data from 15th of the month

SAR provides historical system performance data including CPU, memory, I/O, and network statistics.

22. Describe how you would create an ext4 file system from a raw disk.

Answer: Follow these steps:

# 1. Identify the disk/partition
lsblk          # List block devices

# 2. Create the file system
mkfs.ext4 /dev/sda1

# 3. Verify the file system
blkid /dev/sda1

# 4. Mount the file system
mkdir /mnt/data
mount /dev/sda1 /mnt/data

# 5. Make it permanent by adding to /etc/fstab
echo "/dev/sda1 /mnt/data ext4 defaults 0 2" >> /etc/fstab

23. How would you use NFS to share a directory?

Answer: On the NFS server:

# 1. Install NFS server
apt-get install nfs-kernel-server

# 2. Edit /etc/exports to add shared directory
/shared_dir 192.168.1.0/24(rw,sync,no_subtree_check)

# 3. Export the directory
exportfs -a

# 4. Start NFS service
systemctl start nfs-kernel-server

On the NFS client:

# 1. Install NFS client
apt-get install nfs-common

# 2. Mount the shared directory
mount -t nfs server_ip:/shared_dir /mnt/nfs

24. What is a chroot jail and when is it used?

Answer: A chroot jail is a technique that changes the root directory for a process and its children to a specific directory. It restricts the process from accessing files outside this directory. Common uses:

  • Running services with limited filesystem access for security
  • Isolating applications in testing environments
  • Preventing privilege escalation attacks
  • Running legacy applications with specific library requirements

25. How would you recover a deleted file in Linux?

Answer: Depending on your situation:

From backups:

# Restore from backup system
tar -xf backup.tar.gz deleted_file

Using recovery tools (before disk is reused):

# For ext file systems
extundelete /dev/sda1 --restore-file path/to/deleted_file

# For other file systems
testdisk /dev/sda1

Advanced Linux Interview Questions (3-6 Years Experience)

26. Explain how you would troubleshoot a network issue in Linux.

Answer: A systematic troubleshooting approach:

# 1. Check network interfaces status
ip link show
ifconfig

# 2. Test connectivity
ping destination_ip
traceroute destination_ip

# 3. Check routing table
ip route show
route -n

# 4. Monitor network statistics
netstat -an
ss -an

# 5. Analyze network traffic
tcpdump -i eth0

# 6. Check DNS resolution
nslookup example.com
dig example.com

This approach helps isolate issues at different OSI layers—physical, network, and application layers.

27. What are environment variables and how do you set them?

Answer: Environment variables are dynamic values that affect process behavior. Set them temporarily:

export VAR_NAME=value    # Current session only

Set them permanently by adding to shell profile:

# Add to ~/.bashrc or ~/.bash_profile
export PATH="/custom/path:$PATH"
export JAVA_HOME="/usr/lib/jvm/java-11"

View all environment variables:

env              # Display all variables
echo $VAR_NAME   # Display specific variable

28. Describe the use of awk and sed in text processing.

Answer: Both are powerful text processing tools:

sed (stream editor): Used for filtering and transforming text in a stream

# Replace text
sed 's/old_text/new_text/g' file.txt

# Delete lines matching pattern
sed '/pattern/d' file.txt

# Extract specific lines
sed -n '10,20p' file.txt

awk: Pattern scanning and processing language

# Print specific columns
awk '{print $1, $3}' file.txt

# Filter rows by condition
awk '$2 > 100 {print $0}' file.txt

# Calculate sum of column
awk '{sum+=$1} END {print sum}' file.txt

29. How do you monitor log files in real-time?

Answer: Several methods available:

tail -f /var/log/syslog     # Follow log file in real-time
tail -F /var/log/syslog     # Follows even if file is rotated
less +F /var/log/syslog     # Interactive real-time viewing
watch tail -n 10 /var/log/syslog  # Refresh every 2 seconds

30. What steps would you take to improve the performance of a Linux server?

Answer: A comprehensive optimization approach:

  • Monitor resource usage: Use top, htop, vmstat to identify bottlenecks
  • Optimize applications: Profile code, optimize database queries, implement caching
  • Adjust kernel parameters: Modify sysctl settings for networking, memory management
  • Manage services: Disable unnecessary services to free resources
  • Upgrade hardware: Add RAM, upgrade CPU, use SSD storage when needed
  • Implement load balancing: Distribute traffic across multiple servers
  • Regular maintenance: Clean up logs, temporary files, and unused packages

31. How do you investigate a suspected security breach on a Linux system?

Answer: Follow this incident response procedure:

  • Isolate the system: Disconnect from network to prevent lateral movement
  • Preserve evidence: Create forensic images before conducting analysis
  • Analyze logs: Check /var/log/auth.log, /var/log/syslog for suspicious activity
  • Review running processes: Use ps and netstat to identify unauthorized programs
  • Analyze filesystem: Look for unauthorized files, SUID binaries, rootkits
  • Rotate credentials: Change passwords, SSH keys, API tokens
  • Patch vulnerabilities: Apply security updates that were exploited
  • Rebuild if necessary: Reinstall OS on compromised systems rather than simple patching

32. What is the difference between ramfs, rootfs, and tmpfs?

Answer: All are RAM-based file systems with key differences:

  • ramfs: Simple RAM-based file system that grows dynamically and cannot be limited in size. Can consume all available memory causing system crash
  • rootfs: Virtual file system automatically mounted at system boot. Acts as the root mount point for the Linux kernel
  • tmpfs: Enhanced RAM-based file system with size limits and swap support. Safer than ramfs as it won’t consume all memory. Commonly mounted at /tmp and /run

33. What is the purpose of initramfs during the boot process?

Answer: initramfs (initial RAM file system) is a small file system loaded early during Linux boot with these purposes:

  • Provides essential drivers needed to mount the real root filesystem
  • Handles hardware detection and module loading
  • Contains minimal utilities for pre-boot operations
  • Enables encrypted root filesystem support
  • Allows network boot and custom boot sequences

34. Why would you prefer rsync over scp for transferring multiple files?

Answer: rsync has several advantages over scp:

  • Incremental transfers: Only transfers changed portions of files, saving bandwidth
  • Compression: Automatically compresses data during transfer
  • Resume capability: Can resume interrupted transfers without retransmitting entire files
  • Bandwidth limiting: Can limit transfer speed to avoid network saturation
  • Deletion synchronization: Can delete files at destination that don’t exist at source
  • Preservation of attributes: Maintains file permissions, ownership, and timestamps

Example for transferring batch files:

rsync -avz --progress source_dir/ user@remote:/destination_dir/

35. How do you design Linux systems for scalability?

Answer: Design principles for scalable systems:

  • Stateless architecture: Applications should not rely on local state, enabling easy horizontal scaling
  • Horizontal scaling: Add more servers rather than upgrading single server resources
  • Load balancing: Distribute traffic across multiple servers
  • Automation: Use configuration management (Ansible, Puppet) for provisioning and deployment
  • Containerization: Use Docker and orchestration platforms for flexible resource allocation
  • Database optimization: Implement sharding, replication, and read replicas
  • Caching layers: Use Redis, Memcached for reducing database load
  • Monitoring and alerting: Implement comprehensive monitoring for early issue detection

Conclusion

These 35 Linux interview questions cover the breadth of topics you’ll encounter across all experience levels. Whether preparing for a role at Google, Amazon, Salesforce, Flipkart, or any other organization, strong fundamentals combined with practical troubleshooting skills are essential. Focus on understanding the “why” behind each command and concept rather than memorizing answers. Practice these concepts in real environments, and you’ll be well-prepared for your Linux system administration interview.

Regular hands-on practice with Linux systems, working through real-world scenarios, and staying updated with latest tools and best practices will significantly enhance your interview performance and career growth in Linux system administration.


Leave a Reply

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