Linux Interview Questions & Answers
Linux Interview Questions & Answers
o The GNU Project provides essential utilities and tools that, when
combined with the Linux kernel, form a complete operating system.
o Examples include Ubuntu, Debian, CentOS, Fedora, Arch Linux, and Red
Hat Enterprise Linux (RHEL).
o You can navigate directories using commands like cd, ls, pwd, mkdir,
and rmdir.
o You can create a file using the touch command, e.g., touch filename.
o You can view the contents of a file using commands like cat, less, more,
or tail.
o Use the chmod command, e.g., chmod u+x filename to give the owner
execute permission.
o Use commands like systemctl start, systemctl stop, and systemctl restart
for systems using systemd.
o Use the find command to search for files based on criteria like name,
type, or size.
o Use commands like tar and gzip or bzip2 to compress and decompress
files.
o Use the kill command with the process ID (PID) to terminate a process,
or killall to terminate processes by name.
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.
o Use package management tools like apt (Advanced Package Tool), yum
(Yellowdog Updater, Modified), or dnf (Dandified Yum) to install
software packages from repositories.
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.
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.
o Use tools like top, htop, vmstat, and sar to monitor system performance
metrics such as CPU usage, memory utilization, and disk activity.
o The /tmp directory is used for temporary file storage by programs and
users, typically cleared upon system reboot to free up disk space.
51. What is the difference between soft link and hard link?
• Hard Link:
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.
• 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
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
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.
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
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.
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.
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.
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.
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
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?
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.
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: