Linux, an open-source, Unix-like operating system, has become integral to various computing environments, from servers and desktops to embedded systems. Its versatility, security, and robustness make it a preferred choice for many organizations. As a result, proficiency in Linux is highly sought after in the tech industry. Whether you’re a beginner or an experienced professional, preparing for a Linux interview requires a solid understanding of both fundamental and advanced concepts. This comprehensive guide presents over 100 Linux interview questions and answers, categorized by difficulty levels, to aid your preparation.
Table of Contents
- Beginner-Level Linux Interview Questions
- Intermediate-Level Linux Interview Questions
- Advanced-Level Linux Interview Questions
- Linux Administration Interview Questions
- Linux Troubleshooting Interview Questions
- Linux Networking Interview Questions
Beginner-Level Linux Interview Questions
These questions cover the foundational aspects of Linux, suitable for individuals new to the operating system.
1. What is Linux?
Linux is a free, open-source, Unix-like operating system kernel developed by Linus Torvalds. It serves as the foundation for various distributions designed for systems, servers, embedded devices, mobile devices, and mainframes. Linux supports major computer platforms such as ARM, x86, and SPARC.
2. Explain the basic features of the Linux OS.
Some fundamental features of Linux include:
- Open Source: Freely available and modifiable by users.
- Security: Utilizes security auditing and password authentication features, making it more secure than many other operating systems.
- Software Repository: Offers a personal software repository for easy access to applications.
- Multilingual Support: Supports different language keyboards, catering to users worldwide.
- User Interfaces: Provides both Command-Line Interface (CLI) and Graphical User Interface (GUI) to accommodate various user preferences.
3. Who invented Linux? Explain the history of Linux.
Linux was created by Linus Torvalds in 1991. As a student at the University of Helsinki, Finland, Torvalds sought a free academic version of Unix, leading him to develop the Linux kernel. The initial version, 0.01, was released as open-source software under the GNU General Public License (GPL), inviting global contributions that have shaped Linux into a versatile operating system used in various applications, from server administration to network management.
4. What is the difference between Linux and Unix?
While Linux and Unix share similarities, key differences include:
- Cost: Linux distributions are often free, whereas Unix systems may have associated costs.
- User Interface: Linux primarily uses a GUI with an optional command-line interface, whereas Unix traditionally relies on the command-line interface.
- Portability: Linux is portable across various hardware platforms; Unix is not as portable.
- Development: Linux is developed by a global community; Unix was developed by AT&T developers.
- Usage: Linux is commonly used in home-based PCs and phones; Unix is typically used in server systems.
5. What is the Linux Kernel?
The Linux Kernel is the core component of the Linux operating system. It acts as a bridge between software applications and hardware, managing system resources and hardware communication. The kernel handles tasks such as process management, memory management, and device drivers, ensuring system stability and efficiency.
6. What is BASH?
BASH (Bourne Again Shell) is a Unix shell and command processor written by Brian Fox for the GNU Project. It serves as a replacement for the Bourne Shell and is widely used as the default shell in many Linux distributions. BASH allows users to execute commands, run scripts, and automate tasks, providing a powerful interface for interacting with the operating system.
7. What is LILO?
LILO (Linux Loader) is a boot loader for Linux operating systems. It is responsible for loading the Linux kernel into memory and starting the operating system. LILO can boot Linux from hard disks and floppy disks and can also boot other operating systems, making it a versatile tool in multi-boot environments.
8. What is a Shell in Linux?
A shell in Linux is a command-line interpreter that provides a user interface for accessing the services of the operating system. It allows users to execute commands, run programs, and perform various tasks by typing commands into the terminal. Commonly used shells include BASH, Zsh, and Fish.
9. What is CLI?
CLI (Command-Line Interface) is a text-based user interface used to interact with the operating system. Users input commands as text, and the system responds with text-based output. CLI is powerful for performing administrative tasks, scripting, and automating processes, offering greater control over the operating system compared to graphical interfaces.
10. What is a Linux Distribution?
A Linux Distribution (distro) is a complete operating system package that includes the Linux kernel, system utilities, applications, and package management systems. Distributions are tailored for different purposes and user preferences.
11. What are some popular Linux distributions?
Some commonly used Linux distributions include:
- Ubuntu – User-friendly, widely used for desktops and servers.
- Debian – A stable distribution with a large repository of software packages.
- Fedora – A cutting-edge distribution with the latest features.
- CentOS – A free alternative to Red Hat Enterprise Linux (RHEL).
- Arch Linux – A lightweight and customizable distribution.
- Kali Linux – Specialized for penetration testing and security research.
12. What is the root user in Linux?
The root user is the superuser in Linux with complete administrative control over the system. The root user has permissions to modify system files, install software, create and remove users, and configure system settings.
13. What is the difference between soft links and hard links?
- Hard Link: A direct reference to the original file’s data blocks. Even if the original file is deleted, the data remains accessible.
- Soft Link (Symbolic Link): A pointer to the original file. If the original file is deleted, the soft link becomes invalid.
ln original_file hard_link
ln -s original_file soft_link
14. What is a process in Linux?
A process is an instance of a running program. Linux assigns a unique Process ID (PID) to every running process. You can check running processes using:
ps aux
or
top
15. What are the different states of a process in Linux?
A process in Linux can be in one of the following states:
- Running (R) – Actively executing.
- Sleeping (S or D) – Waiting for a resource.
- Stopped (T) – Paused or suspended.
- Zombie (Z) – Completed execution but not removed from the process table.
16. How do you kill a process in Linux?
To terminate a process, you can use:
- kill command: bashCopy code
kill <PID>
pkill command (by name):
pkill process_name
killall command:
killall process_name
htop (interactive process manager)
17. What is a daemon process in Linux?
A daemon is a background process that runs continuously without user intervention. Common daemons include:
cron
– Schedules jobs.httpd
– Apache web server.sshd
– Secure Shell (SSH) server.
18. What is the difference between foreground and background processes?
- Foreground Process – Runs interactively and takes control of the terminal until it finishes.
- Background Process – Runs in the background without blocking terminal access.
To send a process to the background:
command &
To move a process to the foreground:
fg %job_id
19. How do you check system resource usage in Linux?
You can use the following commands:
top
– Displays real-time process and system information.htop
– An enhanced version oftop
.vmstat
– Shows CPU and memory usage.free -m
– Displays memory usage.df -h
– Shows disk space usage.du -sh /path
– Displays directory size.
20. How do you change file permissions in Linux?
The chmod
command is used to change file permissions. Permissions are represented as:
- r (read) = 4
- w (write) = 2
- x (execute) = 1
To give full permission (read, write, execute) to the owner:
chmod 755 filename
To give read and write permission to everyone:
chmod 666 filename
To remove write permission for others:
chmod o-w filename
21. What is the difference between absolute and relative file paths?
- Absolute Path: The full path from the root directory (
/
). Example:
/home/user/documents/file.txt
Relative Path: A path relative to the current directory. Example:
./documents/file.txt
22. How do you find a file in Linux?
You can use the following commands:
find
– Searches files based on name, type, size, etc.
find /path -name “filename”
locate
– Searches using a pre-built database.
locate filename
which
– Finds the location of executable commands.
which bash
23. What is the purpose of the /etc/passwd
file?
The /etc/passwd
file stores user account information, including:
- Username
- User ID (UID)
- Group ID (GID)
- Home directory
- Shell type
You can view its content using:
cat /etc/passwd
24. What is the difference between cron
and at
?
- cron – Schedules repetitive tasks at specific times.
- at – Schedules one-time tasks.
To list scheduled cron
jobs:
crontab -l
To add a new cron
job:
crontab -e
To schedule a one-time job with at
:
at 5pm
Then enter the command to execute.
25. How do you check the Linux kernel version?
You can check the kernel version using:
uname -r
Alternatively, you can use:
cat /proc/version
26. What is grep
in Linux?
grep
is used to search for patterns in text files.
Example:
grep “error” logfile.txt
To search recursively in all files:
grep -r “error” /var/log/
27. What is awk
in Linux?
awk
is a powerful text processing tool used for pattern matching.
Example:
awk ‘{print $1}’ filename.txt
This prints the first column of a file.
28. How do you view the contents of a file in Linux?
You can use:
cat filename
– Displays the entire file.less filename
– Allows scrolling through a file.head filename
– Shows the first 10 lines.tail filename
– Shows the last 10 lines.nano filename
– Opens the file in a text editor.
29. How do you mount and unmount a device in Linux?
To mount a device:
mount /dev/sdb1 /mnt
To unmount:
umount /mnt
To view mounted devices:
df -h
30. What is the purpose of the ls
command?
The ls
command lists files and directories.
Common options:
ls -l # Long listing format
ls -a # Show hidden files
ls -lh # Human-readable sizes
ls -t # Sort by modification time
31 What is the difference between cp
, mv
, and rm
commands?
cp
(Copy) – Copies files from one location to another. bashCopy codecp source_file destination/
mv
(Move/Rename) – Moves files or renames them. bashCopy codemv oldname newname
rm
(Remove/Delete) – Deletes files or directories. bashCopy coderm filename rm -r directory
32. What is the purpose of the df
and du
commands?
df
(Disk Free) – Displays disk space usage. bashCopy codedf -h
du
(Disk Usage) – Shows disk usage for files and directories. bashCopy codedu -sh /path
33. How do you change the hostname in Linux?
To temporarily change the hostname:
hostname new-hostname
To permanently change the hostname:
sudo nano /etc/hostname
sudo nano /etc/hosts # Update the old hostname references
Then restart the system.
34. What are environment variables in Linux?
Environment variables are global settings affecting shell behavior.
To view environment variables:
printenv
To set an environment variable:
export VAR_NAME=value
35. How do you compress and extract files in Linux?
- Compress a file using
tar
bashCopy codetar -czvf archive.tar.gz filename/
- Extract a tar.gz file bashCopy code
tar -xzvf archive.tar.gz
- Compress using
zip
bashCopy codezip archive.zip filename
- Extract a zip file bashCopy code
unzip archive.zip
36. What is the purpose of /etc/fstab
?
The /etc/fstab
file contains static information about file system mounts. It tells Linux which partitions should be automatically mounted at boot.
View its content using:
cat /etc/fstab
37. What is a swap partition?
A swap partition acts as virtual memory when physical RAM is full. It prevents system crashes by temporarily storing inactive processes.
To check swap usage:
swapon -s
free -m
38. How do you add a new user in Linux?
To add a new user:
sudo useradd -m username
sudo passwd username
To add a user to the sudo group:
sudo usermod -aG sudo username
39. How do you delete a user in Linux?
To remove a user but keep their home directory:
sudo userdel username
To remove the user along with their home directory:
sudo userdel -r username
40. What is the difference between su
and sudo
?
su
(Switch User) – Switches to another user’s account. bashCopy codesu username
sudo
(Superuser Do) – Runs commands with administrative privileges. bashCopy codesudo apt update
41. What is the /dev
directory used for?
The /dev
directory contains device files that represent hardware components. Examples:
/dev/sda1
– First partition of the primary disk./dev/null
– A special file that discards any data written to it.
42. How do you list open ports in Linux?
You can check open ports using:
netstat -tulnp
or
ss -tulnp
43. What is the iptables
command used for?
iptables
is used to configure firewall rules in Linux.
To list firewall rules:
sudo iptables -L -v -n
To block an IP address:
sudo iptables -A INPUT -s 192.168.1.100 -j DROP
44. How do you check system logs in Linux?
System logs are stored in /var/log
. Common logs include:
/var/log/syslog
– General system logs./var/log/auth.log
– Authentication logs./var/log/dmesg
– Kernel messages.
To view logs:
cat /var/log/syslog
45. What is crontab
and how is it used?
crontab
is used to schedule recurring tasks.
To edit a crontab file:
crontab -e
Example cron job (runs every day at midnight):
0 0 * * * /path/to/script.sh
46. What is the difference between apt
and yum
?
apt
(Advanced Package Tool) – Used in Debian-based distributions (Ubuntu, Debian).yum
(Yellowdog Updater Modified) – Used in RHEL-based distributions (CentOS, Fedora).
Example:
sudo apt install package_name # Debian
sudo yum install package_name # RHEL
47. How do you change a user’s password in Linux?
To change your own password:
passwd
To change another user’s password:
sudo passwd username
48. What is the sed
command used for?
sed
(Stream Editor) is used for text manipulation.
Example: Replace all occurrences of “old” with “new” in a file:
sed -i 's/old/new/g' filename.txt
49. What is a symbolic link?
A symbolic link (or soft link) is a pointer to another file.
To create a symbolic link:
ln -s target_file link_name
50. How do you schedule a shutdown in Linux?
To shut down after 10 minutes:
shutdown -h +10
To cancel a scheduled shutdown:
shutdown -c
51. How do you reboot a Linux system from the terminal?
To reboot the system immediately:
sudo reboot
Or use:
sudo shutdown -r now
52. What is the /proc
directory used for?
The /proc
directory contains virtual files that provide information about system processes and hardware. Examples:
/proc/cpuinfo
– CPU details/proc/meminfo
– Memory usage/proc/uptime
– System uptime
To check CPU info:
cat /proc/cpuinfo
53. What is the difference between hard links and soft links?
- Hard Link: Points directly to the data on disk, even if the original file is deleted.
- Soft Link (Symbolic Link): Points to the filename instead of data.
Example:
bashCopy codeln file1 hardlink
ln -s file1 softlink
54. How do you list all installed packages in Linux?
- Debian-based (Ubuntu, Debian): bashCopy code
dpkg --list
- RedHat-based (RHEL, CentOS): bashCopy code
rpm -qa
55. How do you find the process consuming the most CPU?
top
or
ps aux --sort=-%cpu | head
56. How do you find the process consuming the most memory?
ps aux --sort=-%mem | head
57. What is the difference between kill
and pkill
?
kill
– Terminates a process using its PID. bashCopy codekill 1234
pkill
– Terminates a process by its name. bashCopy codepkill firefox
58. How do you check the default run level in Linux?
Use the following command:
runlevel
59. What is the difference between /etc/passwd
and /etc/shadow
?
/etc/passwd
– Stores user account details./etc/shadow
– Stores encrypted user passwords.
60. How do you find which shell you are using?
echo $SHELL
61. How do you check system uptime?
uptime
62. What is the command to display disk usage by directory?
du -sh *
63. How do you check memory usage in Linux?
free -m
64. How do you check active network connections?
netstat -tulnp
or
ss -tulnp
65. How do you list open files used by a process?
bashCopy codelsof -p PID
66. How do you find the full path of a command?
which ls
or
whereis ls
67. How do you create an empty file in Linux?
touch filename
68. How do you change file permissions in Linux?
To give full permissions:
chmod 777 filename
To remove all permissions:
chmod 000 filename
69. What is the nohup
command used for?
It allows a command to run even after logging out.
nohup command &
70. How do you find the size of a file in Linux?
ls -lh filename
71. How do you restart a service in Linux?
For systemd-based systems:
sudo systemctl restart service_name
72. What is the purpose of /etc/hosts
?
It maps IP addresses to hostnames.
To add an entry:
sudo nano /etc/hosts
73. How do you list all services running on Linux?
systemctl list-units --type=service
74. How do you create a tar archive?
bashCopy codetar -cvf archive.tar files/
75. How do you check the Linux kernel version?
uname -r
76. What is the rsync
command used for?
It is used to copy/synchronize files efficiently.
rsync -av source/ destination/
77. How do you add a user to a group?
sudo usermod -aG group_name username
78. How do you find the MAC address of a network interface?
ip link show eth0
79. How do you clear the terminal screen?
clear
80. What is the difference between df
and du
?
df
– Shows disk space usage of partitions.du
– Shows disk usage of directories.
81. What does the tee
command do?
It reads input and writes to a file and standard output.
ls | tee file.txt
82. How do you rename a file in Linux?
mv oldfile newfile
83. How do you create a directory in Linux?
mkdir dirname
84. What is the command to display the last 10 lines of a file?
tail filename
85. How do you find a file by name in Linux?
bashCopy codefind / -name "filename"
86. What is chmod 755
?
- Owner: Read, Write, Execute
- Group & Others: Read, Execute
87. How do you disable root login via SSH?
Edit the /etc/ssh/sshd_config
file and set:
PermitRootLogin no
88. How do you remove duplicate lines from a file?
sort file.txt | uniq
89. How do you enable a service to start on boot?
sudo systemctl enable service_name
90. How do you check listening ports?
netstat -tulnp
91. How do you check DNS resolution?
nslookup google.com
92. What is df -h
used for?
Displays disk space usage in human-readable format.
93. How do you check CPU temperature?
sensors
94. What is grub
?
GRUB (Grand Unified Bootloader) is used to boot Linux.
95. How do you exit from vi
editor?
:q
→ Exit:q!
→ Exit without saving:wq
→ Save and exit
96. How do you kill all processes by name?
pkill process_name
97. How do you check network interface details?
ip a
98. What is the purpose of /etc/resolv.conf
?
It configures DNS servers.
99. How do you find system information?
uname -a
100. How do you monitor real-time log updates?
tail -f /var/log/syslog