0% found this document useful (0 votes)
40 views

Linux Interview Questions & Answers

This document provides an overview of 100 important Linux interview questions and answers organized across several categories including the Linux kernel, file systems, shells and commands, processes and services, system administration, and advanced topics. The questions cover fundamental concepts such as the structure of the Linux file system, navigating directories, permissions, running processes, installing software, and monitoring system performance.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
40 views

Linux Interview Questions & Answers

This document provides an overview of 100 important Linux interview questions and answers organized across several categories including the Linux kernel, file systems, shells and commands, processes and services, system administration, and advanced topics. The questions cover fundamental concepts such as the structure of the Linux file system, navigating directories, permissions, running processes, installing software, and monitoring system performance.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 15

DevOps Shack

100 important Linux Interview


Questions and Answers
1. What is Linux?

o Linux is an open-source operating system kernel originally developed


by Linus Torvalds in 1991.

2. Explain the significance of the GNU Project in relation to Linux.

o The GNU Project provides essential utilities and tools that, when
combined with the Linux kernel, form a complete operating system.

3. Define a Linux distribution.

o A Linux distribution is a collection of software packages based on the


Linux kernel, often including utilities, libraries, and a package
management system.

4. Name a few popular Linux distributions.

o Examples include Ubuntu, Debian, CentOS, Fedora, Arch Linux, and Red
Hat Enterprise Linux (RHEL).

5. Differentiate between Unix and Linux.

o Unix refers to a family of operating systems developed in the late


1960s, while Linux is an independent Unix-like operating system
developed by Linus Torvalds.
File System and Navigation
6. Explain the file system hierarchy in Linux.

o The Filesystem Hierarchy Standard (FHS) defines the structure of


directories in Linux, such as /bin for binaries, /etc for configuration files,
and /home for user data.

7. What is the root directory in Linux?

o The root directory, denoted by /, is the top-level directory from which


all other directories and files stem.

8. How do you navigate directories in Linux?

o You can navigate directories using commands like cd, ls, pwd, mkdir,
and rmdir.

9. How do you create a file in Linux?

o You can create a file using the touch command, e.g., touch filename.

10. How do you view the contents of a file in Linux?

o You can view the contents of a file using commands like cat, less, more,
or tail.

Shell and Command Line


11. Define a shell in Linux.

o A shell is a command-line interpreter that provides a user interface to


interact with the operating system.

12. Name a few popular shells in Linux.

o Popular shells include Bash, Zsh, Ksh, and Tcsh.

13. Explain the difference between . and .. in Linux.

o . refers to the current directory, while .. refers to the parent directory.

14. What is grep in Linux?

o grep is a command-line utility for searching plain-text data sets for


lines that match a regular expression.
15. How do you change file permissions in Linux?

o Use the chmod command, e.g., chmod u+x filename to give the owner
execute permission.

Processes and Services


16. How do you list all processes running on a system in Linux?

o Use the ps command to list processes, and ps aux to display all


processes.

17. What is a daemon in Linux?

o A daemon is a background process that runs continuously, often


providing services like web servers or database servers.

18. How do you start, stop, and restart services in Linux?

o Use commands like systemctl start, systemctl stop, and systemctl restart
for systems using systemd.

19. What is SSH, and how is it used?

o SSH (Secure Shell) is a cryptographic network protocol used for secure


remote login and command execution between two networked
computers.

20. What is sudo in Linux?

o sudo allows users to execute commands with the security privileges of


another user, typically the superuser (root).
System Administration
21. How do you search for files in Linux?

o Use the find command to search for files based on criteria like name,
type, or size.

22. How do you compress and decompress files in Linux?

o Use commands like tar and gzip or bzip2 to compress and decompress
files.

23. How do you kill a process in Linux?

o Use the kill command with the process ID (PID) to terminate a process,
or killall to terminate processes by name.

24. What is a symbolic link in Linux?

o A symbolic link (symlink) is a special file that points to another file or


directory.

25. How do you check system information in Linux?

o Use commands like uname, hostname, cat /etc/os-release, and


lsb_release -a to check system information.
Advanced Topics
26. What is SELinux, and how does it enhance security in Linux?

o SELinux (Security-Enhanced Linux) is a Linux kernel security module that


provides mandatory access control (MAC) policies, restricting the
actions that processes and users can perform based on defined security
policies.

27. How do you schedule recurring tasks in Linux?

o Use the cron daemon and crontab command to schedule recurring


tasks by specifying the desired execution time and frequency.

28. Explain the purpose of the /dev directory in Linux.

o The /dev directory contains device files that represent physical and
virtual devices connected to the system, allowing user programs to
interact with hardware components.

29. What is a swap space in Linux, and why is it used?

o Swap space is a dedicated area of disk storage used as virtual memory


by the operating system when physical RAM is insufficient to hold all
running processes and data.

30. How do you gracefully shut down or reboot a Linux system?

o Use commands like shutdown or reboot with appropriate options to


initiate a system shutdown or reboot process, allowing running
processes to cleanly terminate and system services to shut down in an
orderly manner.

31. What is the purpose of the /etc/passwd file?

o The /etc/passwd file stores essential user information, such as


usernames, user IDs, home directories, and shell types.

32. Explain the significance of the /etc/shadow file.

o The /etc/shadow file stores encrypted password information for user


accounts, enhancing security by keeping password hashes inaccessible
to regular users.
33. What is an inode in Linux?

o An inode is a data structure that represents a file or directory on a file


system. It stores metadata such as permissions, ownership, and file
type.

34. How do you determine the IP address of a Linux system?

o Use the ifconfig or ip addr command to display network interface


information, including IP addresses.

35. What is the purpose of the /proc filesystem in Linux?

o The /proc filesystem provides an interface to kernel data structures and


system information, allowing processes to access and manipulate
system parameters.

36. How do you install software packages in Linux?

o Use package management tools like apt (Advanced Package Tool), yum
(Yellowdog Updater, Modified), or dnf (Dandified Yum) to install
software packages from repositories.

37. Explain the role of the /etc/fstab file in Linux.

o The /etc/fstab file maintains a list of filesystems and their


corresponding mount points, facilitating automatic mounting of
filesystems during system boot.

38. What is a kernel panic in Linux?

o A kernel panic occurs when the Linux kernel encounters a critical error
from which it cannot recover, resulting in a system halt or crash.

39. How do you check available disk space in Linux?

o Use commands like df -h to display disk usage in a human-readable


format, showing available disk space on mounted filesystems.

40. What is the purpose of the /var directory in Linux?

o The /var directory contains variable data files that are expected to grow
during normal system operation, such as log files, spool directories, and
temporary files.
41. How do you change the hostname of a Linux system?

o Modify the /etc/hostname file and update the hostname using the
hostnamectl command.

42. What is a runlevel in Linux?

o A runlevel is a predefined operating state of a Unix-like system,


representing a specific configuration of services and system processes.

43. Explain the significance of the /etc/inittab file.

o The /etc/inittab file is used by the init process to determine the


system's default runlevel and initiate system startup and shutdown
procedures.

44. What is SELinux, and how does it enhance security in Linux?

o SELinux (Security-Enhanced Linux) is a Linux kernel security module that


provides mandatory access control (MAC) policies, restricting the
actions that processes and users can perform based on defined security
policies.

45. How do you monitor system performance in Linux?

o Use tools like top, htop, vmstat, and sar to monitor system performance
metrics such as CPU usage, memory utilization, and disk activity.

46. Explain the purpose of the /tmp directory in Linux.

o The /tmp directory is used for temporary file storage by programs and
users, typically cleared upon system reboot to free up disk space.

47. What is a swap space in Linux, and why is it used?

o Swap space is a dedicated area of disk storage used as virtual memory


by the operating system when physical RAM is insufficient to hold all
running processes and data.

48. How do you schedule recurring tasks in Linux?

o Use the cron daemon and crontab command to schedule recurring


tasks by specifying the desired execution time and frequency.
49. Explain the purpose of the /etc/hosts file in Linux.

o The /etc/hosts file is used to map IP addresses to hostnames and vice


versa, allowing the system to resolve domain names without DNS.

50. What is the purpose of the /proc filesystem in Linux?

o The /proc filesystem provides an interface to kernel data structures and


system information, allowing processes to access and manipulate
system parameters.

51. What is the difference between soft link and hard link?

• Soft Link (Symbolic Link):

o It's a pointer to another file or directory.


o Can link files across filesystems.
o If the original file is removed, the link becomes 'dangling'.
o Usage: ln -s source_file link_name

• Hard Link:

o It's a directory entry pointing to the same inode as another directory


entry.
o Cannot link directories or files across filesystems.
o If the original file is removed, the link remains valid.
o Usage: ln source_file link_name

52. Explain the concept of inodes in Linux.

• Inodes are data structures in Unix-based filesystems containing metadata


about files, such as ownership, permissions, size, and file type. Every file and
directory on a Unix filesystem is represented by an inode. Inodes do not store
the actual file content but rather act as a reference to where the data is stored
on the disk.

53. How can you find out which processes are consuming the most memory
on a Linux system?

• You can use the top command to display running processes and their resource
usage, including memory. Press Shift + M to sort processes by memory usage.

54. What is the purpose of the chmod command in Linux?


• chmodis used to change the permissions of files or directories. It stands for
"change mode." It can be used to grant or revoke read, write, and execute
permissions for the owner, group, and others.

55. How can you recursively delete a directory in Linux?

• Use the rm command with the -r (recursive) option. For example:


• rm -r directory_name

56. Explain the difference between grep, egrep, and fgrep.

• grep: It's the basic pattern searching command. It uses basic regular
expressions.
• egrep: It's an enhanced version of grep that supports extended regular
expressions.
• fgrep: It's a fast version of grep that searches for fixed strings and doesn't
interpret regular expressions.

57. How can you find all files modified in the last 7 days?

• You can use the find command with the -mtime option. For example:
• find /path/to/search -type f -mtime -7

58. Explain the cron and at commands in Linux.

• cron: It's a time-based job scheduler in Unix-like operating systems. It allows


users to schedule jobs (commands or shell scripts) to run periodically at fixed
times, dates, or intervals.
• at: It's used to schedule a one-time task to be executed at a specified time in
the future. Unlike cron, which is for recurring tasks, at is for one-time tasks.

59. How can you list all open ports on a Linux system?

• You can use the netstat or ss command to list open ports. For example:
• netstat -tuln

Or

ss -tuln
60. Explain the purpose of the awk command in Linux.
o awk is a powerful text processing tool in Unix-like operating systems. It's
used for searching, filtering, and processing text or data files,
particularly when data is presented in columnar format. It operates on a
per-line basis and allows users to specify patterns and actions to be
performed on those lines.
61. How can you change the default shell for a user in Linux?

o You can use the chsh command to change the default shell for a user.
For example:
o chsh -s /bin/bash username

62. What is a systemd service in Linux?

o systemdis a system and service manager for Linux operating systems. A


systemd service is a unit configuration file that defines how a service
should behave, including its dependencies, startup and shutdown
behavior, and execution environment.

63. How can you check the disk space usage of a Linux system?

o You can use the df command to display disk space usage. For more
detailed information, you can use du to check disk usage of specific
directories.
64. Explain the difference between tar and zip commands.
o tar: It's used to create and manipulate tar archives, which are
collections of files wrapped up in one file. It's commonly used in Unix-
like systems.
o zip: It's used to compress files and create Zip archives. It's more
common on Windows systems but can be used on Unix-like systems
with appropriate software installed.

65. How can you find out which shell you are currently using?

o You can use the echo command with the SHELL environment variable.
For example:
o echo $SHELL
66. Explain the purpose of the sudo command in Linux.
o sudo (superuser do) is a command used in Unix-like operating systems
to allow users to execute commands with the security privileges of
another user, typically the superuser (root). It's commonly used to
perform administrative tasks that require elevated privileges.

67. How can you change the hostname of a Linux system?

o You can change the hostname temporarily using


the hostname command. For example:
o hostname new_hostname

To change it permanently, you would typically edit


the /etc/hostname file and also update the /etc/hosts file if necessary.
68. Explain the purpose of the find command in Linux.
o find is a command-line utility in Unix-like operating systems used to
search for files and directories based on various criteria such as name,
type, size, and permissions. It's a versatile tool for locating files and
performing actions on them.

69. How can you check the version of the Linux kernel?

o You can use the uname command with the -r option to display the
kernel release. For example:
o uname -r

70. What is a shell script and how do you execute it?

o A shell script is a text file containing a sequence of shell commands


that are executed one after another. It allows users to automate tasks
and perform complex operations. To execute a shell script, you need to
make it executable (chmod +x script.sh) and then run it
using ./script.sh.
71. Explain the purpose of the /etc/passwd file in Linux.
o /etc/passwd is a system file in Unix-like operating systems that stores
essential information about user accounts, including usernames, user
IDs (UIDs), group IDs (GIDs), home directories, and default shells.

72. How can you monitor system performance in real-time on a Linux


system?

o You can use tools like top, htop, or glances to monitor system
performance in real-time. These tools display information about CPU,
memory, disk, and network usage, as well as a list of running processes.
73. Explain the purpose of the iptables command in Linux.
o iptables is a command-line utility for configuring the Linux kernel
firewall (netfilter) in Unix-like operating systems. It allows users to set
up rules and policies for packet filtering, network address translation
(NAT), and other networking tasks.

74. How can you determine the IP address of a Linux system?

o You can use the ifconfig or ip addr command to display network


interface information, including IP addresses assigned to the system.

75. What is a symbolic link and how do you create one?

o A symbolic link (or symlink) is a special type of file that serves as a


pointer to another file or directory. To create a symbolic link, you can
use the ln command with the -s option. For example:
o ln -s target_file link_name
76. Explain the purpose of the ps command in Linux.
o ps is a command-line utility for displaying information about processes
running on a Linux system. It can show a snapshot of the current
processes, including their process IDs (PIDs), parent process IDs (PPIDs),
CPU and memory usage, and other attributes.

77. How can you find out the amount of free memory on a Linux system?

o You can use the free command to display information about available
memory and swap space on the system.

78. What is a package manager in Linux and why is it useful?

o A package manager is a software tool used to install, update, and


manage software packages on a Linux system. It automates the process
of software installation and dependency resolution, making it easier for
users to manage their software environment.

79. How can you list all users currently logged into a Linux system?

o You can use the who or w command to list all users currently logged in.
For more detailed information, you can use the last command.
80. Explain the purpose of the rsync command in Linux.
o rsync is a powerful file synchronization and transfer tool in Unix-like
operating systems. It's used to efficiently copy and synchronize files
and directories between two locations, either locally or over a network.

81. How can you create a new user account in Linux?

o You can use the useradd command to create a new user account. For
example:
o useradd username

82. What is a kernel panic in Linux and how can you troubleshoot it?

o A kernel panic is a critical error in the Linux kernel that results in the
system becoming unresponsive and requiring a reboot. It's often
caused by hardware failures, driver issues, or kernel bugs. To
troubleshoot a kernel panic, you can analyze the kernel panic message,
review system logs, and perform hardware diagnostics.

83. How can you determine the size of a directory in Linux?

o You can use the du command to display the disk usage of a directory.
For example:
o du -sh directory_name
84. Explain the purpose of the grep command in Linux.
o grep is a command-line utility for searching text patterns in files or
output streams. It's commonly used for pattern matching, text filtering,
and data extraction tasks.

85. How can you find out which Linux distribution and version you are
using?

o You can use the lsb_release command to display Linux Standard Base
(LSB) information, including the distribution and version. For example:
o lsb_release -a

86. What is a runlevel in Linux and how does it work?

o A runlevel is a predefined operating state on a Unix-like system that


determines which services and processes are started or stopped. Linux
systems typically have multiple runlevels, each representing a different
system configuration, such as single-user mode or multi-user mode
with networking.

87. How can you kill a process in Linux?

o You can use the kill command to terminate a process by its process ID
(PID). For example:
o kill PID
88. Explain the purpose of the cron.daily, cron.weekly,
and cron.monthly directories in Linux.
o These directories contain scripts or commands that are executed by
the cron daemon at predefined intervals (daily, weekly, or monthly).
System administrators can place scripts in these directories to automate
routine tasks.

89. How can you check if a Linux system is running in 32-bit or 64-bit mode?

o You can use the uname command with the -m option to display the
machine hardware name, which indicates whether the system is
running in 32-bit or 64-bit mode.
90. Explain the purpose of the sed command in Linux.
o sed (stream editor) is a powerful text processing tool in Unix-like
operating systems. It's used to perform text transformations, such as
search and replace, editing, and filtering, on input streams or files.
91. How can you set up a static IP address on a Linux system?

o You can manually configure network interfaces and set up static IP


addresses in the /etc/network/interfaces file or use tools
like ip or ifconfig to configure network settings.

92. What is a symbolic link and how do you create one?

o A symbolic link (or symlink) is a special type of file that serves as a


pointer to another file or directory. To create a symbolic link, you can
use the ln command with the -s option. For example:
o ln -s target_file link_name
93. Explain the purpose of the journalctl command in Linux.
o journalctl is a command-line utility for querying and displaying logs
from the systemd journal, a centralized logging system in Linux. It
allows users to view and filter log messages based on various criteria,
such as time, severity, and originating unit.

94. How can you list all environment variables in a Linux system?

o You can use the env command to display all environment variables
currently set in the system.
95. What is the purpose of the crontab command in Linux?
o crontab is a command-line utility used to manage user-specific cron
jobs. It allows users to create, edit, list, and remove cron jobs that are
scheduled to run at specified times or intervals.

96. How can you check the status of a systemd service in Linux?

o You can use the systemctl command to check the status of systemd
services. For example:
o systemctl status service_name
97. Explain the purpose of the awk command in Linux.
o awk is a powerful text processing tool in Unix-like operating systems. It's
used for searching, filtering, and processing text or data files,
particularly when data is presented in columnar format. It operates on a
per-line basis and allows users to specify patterns and actions to be
performed on those lines.

98. How can you mount and unmount filesystems in Linux?

o You can use the mount command to mount filesystems and


the umount command to unmount them. For example:
o mount /dev/sdb1 /mnt
o umount /mnt
99. What is the purpose of the traceroute command in Linux?
o traceroute is a command-line utility used to trace the route that
packets take from the local system to a destination host or IP address.
It displays the IP addresses of routers along the path and measures the
round-trip time (RTT) for each hop.

100. How can you find files containing a specific text string in Linux?

o You can use the grep command to search for files containing a specific
text string. For example:

grep -r "search_string" /path/to/search

You might also like