Skip to Content

Top 60 Linux Interview Questions and Answers

In this blog post, we will provide you with the top 60 Linux interview questions and answers. This information is essential for anyone looking to start a career in Linux or for those who are already working in the field and want to take their career to the next level.

We have divided the questions into categories based on experience level: beginner, intermediate, and advanced.

Table of Contents

What is Linux?

Linux is a free and open-source operating system that was created by Linus Torvalds in 1991. It is based on the Unix operating system and can be run on a wide variety of hardware platforms, including personal computers, servers, mainframes, and embedded devices.

What are the benefits of using Linux?

There are many benefits to using Linux, including the following:

  • It is a free and open-source operating system. This means that anyone can access the source code and make changes or improve upon it.
  • It is very stable and reliable. Once you have it installed, you can expect it to run smoothly without any major issues.
  • It has a large community of users and developers who are always willing to help out or provide support if you need it.
  • It is very customizable and can be tailored to fit your specific needs.

 

What are some of the most popular Linux distributions?

Some of the most popular Linux distributions include Ubuntu, Debian, Fedora, and Mint.

What is the difference between a Linux distribution and an operating system?

Linux distribution is a collection of software that is based on the Linux kernel and other open-source software. It is typically packaged together and made available for download. An operating system, on the other hand, is the software that actually runs on a computer and manages all of the hardware and software resources.

What is the Linux kernel?

The Linux kernel is the heart of the Linux operating system. It is responsible for managing all of the system’s resources and providing a platform for user-space applications to run on.

What is a user-space application?

A user-space application is any program that runs outside of the kernel. This includes all of the standard applications that you would use on a daily basis, such as a web browser or database.

What is the shell in Linux?

The shell is a command-line interpreter that allows you to interact with the Linux operating system. It is typically used for system administration tasks or for writing shell scripts.

A shell script is a text file that contains a sequence of commands that are executed by the shell. They are often used to automate repetitive or tedious tasks.

What are some of the most popular text editors for Linux?

Some of the most popular text editors for Linux include Vim, Emacs, and Nano.

What is a package manager in Linux?

A package manager is a software application that helps you manage the software packages that are installed on your system. It can be used to install, remove, or update software packages.

What is the difference between a source package and a binary package?

A source package is a collection of files that are needed to compile a piece of software. A binary package, on the other hand, is a pre-compiled package that is ready to be installed on a system.

What is the apt repository?

The apt repository is a central location where software packages are stored and made available for download.

What is crontab and explain its functionality and explain the format of crontab?

Cron is a daemon that executes commands at specified intervals. These commands are called “cron jobs.”

Crontab is the file that contains the list of cron jobs. It is typically stored in the /etc/crontab file.

The format of a crontab file is as follows:

minute hour day-of-month month day-of-week command

The fields are separated by spaces or tabs. The asterisk character (*) is used to specify all values.

For example, the following crontab entry would execute the “ls” command every minute:

* * * * * ls

The following entry would execute the “backup.sh” script every Sunday at 2:00am:

0 2 * * 0 backup.sh

How to run a shell script in Linux?

To run a shell script, you need to have the appropriate permissions. The easiest way to do this is to use the “chmod” command to make the script executable.

Once the script is made executable, you can run it by typing its path into the command line.

For example, if the “backup.sh” script from the previous question is stored in your home directory, you could run it with the following command:

chmod +x backup.sh

~/backup.sh

What is a Swap Space or Swap Partition in Linux?

A Swap space is an area on a hard disk that is used by the operating system as virtual memory. When physical memory (RAM) is running low, the kernel will move some of the contents of RAM to the swap space. This allows the system to free up some physical memory for other uses.

The swap space can be either a dedicated partition or a file. The size of the swap space should be at least as large as the amount of physical memory in the system. For example, if a system has 4 GB of RAM, the swap space should be at least 4 GB.

How to create a Swap Space in Linux?

To create a new swap space, you can use the “dd” command to create a file of the desired size. For example, to create a 4 GB swap file, you would use the following command:

sudo dd if=/dev/zero of=/swapfile bs=1G count=4

This will create a file called “/swapfile” that is 4 GB in size.

Once the file has been created, you need to format it as a swap file with the following command:

sudo mkswap /swapfile

Finally, you can enable the swap file with the following command:

sudo swapon /swapfile

How to enable and disable Swap Space in Linux?

To enable a swap file, you can use the “swapon” command. For example, to enable the swap file created in the previous question, you would use the following command:

sudo swapon /swapfile

To disable a swap file, you can use the “swapoff” command. For example, to disable the swap file created in the previous question, you would use the following command:

sudo swapoff /swapfile

 

How to check if Swap Space is enabled in Linux?

To check if a swap file is enabled, you can use the “swapon” command with the “-s” option. For example, to check if the swap file created in the previous question is enabled, you would use the following command:

sudo swapon -s

This will print a list of all enabled swap files. If the swap file you’re looking for is not listed, then it is not enabled.

How do I check the size of Swap Space in Linux?

To check the size of a swap file, you can use the “ls” command with the “-lh” option. For example, to check the size of the swap file created in the previous question, you would use the following command:

ls -lh /swapfile

This will print the size of the swap file.

How to check the usage of Swap Space in Linux?

To check the usage of swap space, you can use the “free” command with the “-m” option. For example, to check the usage of swap space on the system, you would use the following command:

free -m

This will print a list of all the available swap space on the system and how much is being used.

What is an Inode in Linux?

An inode is a data structure that stores information about a file or directory on a Linux file system. Each file and directory on a file system has an inode associated with it. The inode stores information such as the file’s size, ownership, permissions, and timestamps.

How to check the Inode Usage on my Linux File System?

To check the inode usage on a Linux file system, you can use the “df” command with the “-i” option. For example, to check the inode usage on the “/” file system, you would use the following command:

df -i /

This will print a list of all file systems and their inode usage.

What is an Absolute Path in Linux?

An absolute path is a file path that starts from the root of the file system. On Linux, the root of the file system is “/”. An absolute path always starts with a “/” character.

For example, the absolute path to the “/etc/passwd” file is “/etc/passwd”.

What is a Relative Path in Linux?

A relative path is a file path that is relative to the current working directory. A relative path does not start with a “/” character.

For example, if the current working directory is “/home/user”, the relative path to the “/etc/passwd” file would be “../../etc/passwd”.

Describe the root account.

The root account is the superuser account on a Linux system. The root account has full privileges and can perform any action on the system.

How to change the password of the root account?

To change the password of the root account, you can use the “passwd” command. For example, to change the password of the root account, you would use the following command:

sudo passwd

How to become the root user in Linux?

To become the root user, you can use the “su” command. For example, to become the root user, you would use the following command:

su -

You will be prompted for the password of the root account. Once you enter the correct password, you will be logged in as the root user.

How to create a new user account in Linux?

To create a new user account, you can use the “useradd” command. For example, to create a new user account with the username “john”, you would use the following command:

sudo useradd john

This will create a new user account with the username “john”. The account will have no password and will not be able to login.

How to delete a user account in Linux?

To delete a user account, you can use the “userdel” command. For example, to delete the user account “john”, you would use the following command:

sudo userdel john

This will delete the user account “john”. Be careful when deleting user accounts, as you can not recover them once they are deleted.

How to change a user’s password in Linux?

To change a user’s password, you can use the “passwd” command. For example, to change the password of the user “john”, you would use the following command:

sudo passwd john

You will be prompted for the new password for the user. Once you enter the new password, the password will be changed.

How to add a user to a group in Linux?

To add a user to a group, you can use the “usermod” command. For example, to add the user “john” to the “wheel” group, you would use the following command:

sudo usermod -aG wheel john

This will add the user “john” to the “wheel” group. The user will now have access to any privileges that the group has.

How to remove a user from a group in Linux?

To remove the user from one of groups, you can invoke the gpasswd command with the –delete flag followed by the user to be removed and the group.

In the example below, the howtouselinux user is removed from the group wheel.

sudo gpasswd --delete howtouselinux wheel

This will remove the user “howtouselinux” from the “wheel” group. The user will no longer have access to any privileges that the group has.

How to check disk size in Linux?

The lsblk command will list all the block devices on your system. The output will show the disk size, type, and other information about each block device.

How to check ip address in Linux?

 The ip addr command will show all the IP addresses assigned to your system.

How to check mac address in linux?

The ifconfig command will show all the network interfaces on your system.

For example, to list all the network interfaces on your system, you would use the following command:

ifconfig -a

This will list all the network interfaces on your system, including the MAC address for each interface.

How to check memory usage in Linux?

The free command will show you the amount of free and used memory on your system.

For example, to check the memory usage on your system, you would use the following command:

free -m

This will show you the amount of free and used memory in megabytes.

How to check CPU usage in Linux?

The top command will show you the running processes on your system and their CPU usage.

This will show you the running processes on your system and their CPU usage. You can press “q” to exit the top command.

What is the issue behind getting an error “filesystem is full”?

When all the inodes are consumed then even though you have free space, you will get the error that filesystem is full. So, to check whether there is space available, we have to use the command df –i.

Sometimes, it may happen file system or storage unit contains the substantial number of small files, and each of the files takes 128 bytes of the inode structure then inode structure fills up, and we will not be able to copy any more file to the disk.

So, to rectify the problem, you need to free the space in inode storage, and you will be able to save more files.

How to check currently logged in users in Linux?

There are many ways to check who is logged in to your system. One way is to use the “w” command. The w command will show you a list of users who are currently logged in to your system.

How to check my cron jobs in Linux?

One way is to use the “crontab -l” command. This command will show you a list of cron jobs that are currently running on your system.

How to check my system logs in Linux?

One way is to use the “tail” command. The tail command will show you the last few lines of a log file.

For example, to view the last few lines of the /var/log/syslog file, you would use the following command:

tail -f /var/log/syslog

This will show you the last few lines of the syslog file. You can press “Ctrl+c” to exit the tail command.

What is the inode in Linux? How is it different from a file?

Inode is a data structure that stores information about a file. Each file has an inode associated with it. The inode contains information such as the file’s owner, permissions, and timestamps.

A file is a collection of data. A file can contain text, images, or anything else. A file does not have an inode associated with it.

How to check for open ports in Linux?

There are many ways to check for open ports in Linux. One way is to use the “netstat” command. The netstat command will show you a list of open ports on your system.

For example, to check for open ports on your system, you would use the following command:

netstat -lnp

This will show you a list of open ports on your system. The “-l” option shows only listening ports. The “-n” option shows numerical addresses. The “-p” option shows the PID and name of the program that is using the port.

How to check my system information in Linux?

There are many ways to check your system information in Linux. One way is to use the “uname” command. The uname command will show you your system’s kernel information.

For example, to check your system information, you would use the following command:

uname -a

This will show you your system’s kernel information. The “-a” option shows all information about your system.

What are soft links? Describe some of the features of soft links.

Answer: Soft Links or Symbolic Link or Symlink are special files which are used as a reference for another directory. Some features of softlinks are:

  • They have a different INODE number with respect to source files or original files.
  • If in case the original file is deleted then a soft link of that file is useless.
  • We cannot update a soft link.
  • Soft links can be used to create links between directories.
  • Soft links are independent of file system boundaries.

 

How to find out which processes are using the most memory in Linux?

There are many ways to check which processes are using the most memory in Linux. One way is to use the “ps” command. The ps command will show you a list of processes and their memory usage.

For example, to find out which processes are using the most memory, you would use the following command:

ps -eo pmem,pid,user,args | sort -k 1 -r | head -10

This will show you a list of processes and their memory usage. The “-e” option shows all processes. The “o pmem,pid,user,args” options format the output to show memory usage, process ID, user, and command. The “sort -k 1 -r” options sort the output by memory usage in reverse order. The “head -10” options show the top 10 processes.

What is Key-based authentication? Explain.

Key-based authentication is a method of authenticating to a server using a private key. The private key is stored on the client machine and is used to encrypt a message that is sent to the server. The server decrypts the message using the corresponding public key and checks for a match. If there is a match, the user is authenticated.

What is a runlevel in Linux? Explain.

A runlevel is a state that a Linux system can be in. There are seven runlevels, numbered 0-6. Runlevel 0 is used for shutting down the system. Runlevel 1 is used for single-user mode. Runlevels 2-5 are used for multi-user mode. Runlevel 6 is used for rebooting the system.

What is SELinux? Explain.

SELinux is a security extension for Linux. It provides a mechanism for controlling access to files and resources. SELinux can be configured to allow or deny access to specific users or groups of users.

SELinux is the abbreviation for Security Enhanced Linux. The access controls for the users can be controlled using SELinux. For example, the users can be stopped from running the scripts and accessing their own home directories. SELinux has the capability to support the access control and security policies. It basically operates on three different modes:

  • Enforcing –to enforce its policies.
  • Permissive –Polices want to apply but will be locked in case of violation.
  • Disabled –SELinux will stay in disabled mode.

 

To check the status of SELinux, just type: #getenfore OR sestatus

What is a shell in Linux? Explain.

A shell is a command-line interpreter that allows you to type commands that are executed by the operating system. The most common shells are the Bourne shell, the C shell, and the Bourne Again shell.

What is SSH? Explain.

SSH is a secure shell that allows you to connect to a remote machine and execute commands. SSH uses encryption to protect the data that is being transferred between the two machines.

What is sudo? Explain.

Sudo is a program that allows you to execute commands as another user. Sudo can be used to execute commands as the root user.

Explain the logical steps to increase the size of LVM partition in Linux

Some logical steps need to be followed to increase the size of LVM partition. These are as follows:

Run the command as per given format:

lvextend -L +500M /dev/<Name of the LVM Partition>

Here, we are extending the size of LVM partition by 500MB.

resize2fs /dev/<Name of the LVM Partition>

You can check the size of partition using ‘df -h’ command

What are the different types of RAID levels in Linux?

RAID 0: It offers striping but no redundancy of data. So, if one drive fails then all data stored on the drives is lost.

RAID 1: It consists of an exact copy (or mirror) of a set of data on two or more disks. A minimum of two drives is needed for this level.

This level provides data redundancy but no striping.

RAID 5: It stripe the data across multiple disks with parity information stored on all drives. A minimum of three disks is needed for this level.

RAID 6: It is similar to RAID 5, but it uses two parity blocks, which are distributed across different drives. So, if two drives fail, then the data can be rebuilt from the parity information. A minimum of four disks is needed for this level.

RAID 10: It combines mirroring and striping to provide redundancy and performance. A minimum of four disks is needed for this level.

Explain LVM Logical volume manager

Answer: LVM stands for Logical volume manager. It is a storage management technology that allows us to administer disk space in a more flexible way. With the help of LVM, we can easily create, resize, and delete logical volumes without unmounting the file system or rebooting the system.

We can also add new hard drives to an existing system and expand the size of existing logical volumes. LVM provides better performance and flexibility as compared to traditional partitioning.

  • A physical volume (PV) is a disk or partition that is used to store data. A PV can be created using the pvcreate command.
  • A logical volume (LV) is a storage area that is created on a PV. An LV can be created using the lvcreate command.
  • A volume group (VG) is a collection of LVs. A VG can be created using the vgcreate command.
  • A partition is a portion of a disk that is used to store data. Partitions can be created using the fdisk or parted commands.
  • A file system is a way of storing and organizing data on a disk. The most common file systems are ext3, ext4, and XFS.

 

 Explain all the fields in the/etc/passwd file?

The /etc/passwd file contains information about the users on a system. Each line in the file contains seven fields, which are separated by colons. The fields are:

  • Username: This is the name of the user.
  • Password: This is an encrypted password for the user. The password is usually stored as an asterisk (*).
  • User ID (UID): This is the numeric user ID for the user.
  • Group ID (GID): This is the numeric group ID for the user.
  • User Information: This field contains information about the user, such as the full name.
  • Home Directory: This is the path to the home directory for the user.
  • Shell: This is the path to the shell for the user.

 

What is /etc/shadow file?

The /etc/shadow file contains information about the users’ passwords. Each line in the file contains nine fields, which are separated by colons. The fields are:

  • Username: This is the name of the user.
  • Password: This is an encrypted password for the user. The password is usually stored as an asterisk (*).
  • Last Password Change: This is the date of the last password change.
  • Minimum Password Age: This is the minimum number of days that must pass before a password can be changed.
  • Maximum Password Age: This is the maximum number of days that a password can be used before it must be changed.
  • Password Expiration: This is the date when the password will expire.
  • Account Expiration: This is the date when the account will expire.
  • Reserved: This field is reserved for future use.

 

Mention some of the networking commands in Linux.

Answer: If you connect a system to a network then you can easily troubleshoot the connection issues related to the system. Below are few of the networking commands used for configuration and troubleshooting.

  • ifconfig
  • traceroute
  • dig
  • telnet
  • nslookup
  • netstat

Write the command to view an existing tar archive and how to extract it?

Answer: The command for viewing tar archive that is already existing: $ tar tvf archive_name.tar

The command to extract an existing tar archive: $ tar xvf archive_name.tar

The command for the creation of new tar archive: $ tar cvf archive_name.tar dirname/

You may be asked one or more command based interview questions in the linux interview. You should prepare yourself with as many commands as you can. There are several commands that are used for tar archive which are commonly asked in the linux interview, so don’t miss to cover this question while going for the linux interview.

How to disable ping to avoid network /ICMP flood

 set the following in/etc/sysctl.conf : net.ipv4.icmp_echo_ignore_all =1

Then “sysctl -p”

Mention the steps to create the partition form a raw disk.

Answer: In case we want to create a new partition form a raw disk, you have to use a tool known as “fdisk utility”. The steps to create a raw disk are as follows:

In case of IDE we use >>> fdisk/dev/hd and in case of SCSI we use >>> fdisk/dev/sd

Then type n for creating a new partition.

After the partition is created type ‘w’.

Explain Network Bonding and also explain the different types of Network bonding?

Answer: Network Bonding as the name implies that it is the process of bonding or joining two or more than two network interfaces to create one interface. It helps in improving the network throughput, bandwidth, redundancy, load balancing as in case any of the interfaces is down; the other one will continue to work. Several types of Network Bonding are available that are based on the kind of bonding method.

Below are the different bonding types in Linux:

  • balance-rr or mode 0 – This is the default mode of network bonding that works on the round-robin policy that means from the first slave to the last, and it is used for fault tolerance and load balancing.
  • active-backup or mode 1 – This type of network bonding works on the active-backup policy that means only one slave will be active and other will work just when another slave fails. This mode is also used for fault tolerance.
  • balance-xor or mode 2 –This type of network bonding sets an exclusive or mode that means source MAC address is XOR’d with the destination address, and thus it provides fault tolerance and load balancing.

 

  • broadcast or mode 3 –This mode sets a broadcast mode to provide fault tolerance, and it should be used for particular purposes. In this type of network bonding, all transmissions are sent to all slave interfaces.
  • 802.3ad or mode 4 –This mode will create the aggregation groups, and all the groups will share the same speed. For this, mode sets an IEEE 802.3ad dynamic link aggregation mode. It is done by particular switch support that supports IEEE 802.3ad dynamic link.
  • balance-tlb or mode 5 –This mode sets a transmit load balancing mode for fault tolerance and load balancing and does not require any switch support.
  • balance-alb or mode 6 –This mode sets an active load balancing to achieve fault tolerance and load balancing.