Categories

Top Answers to Linux Interview Questions

CTA

Linux is among the fastest and most powerful operating systems used in computers. Over 90 percent of the world’s fastest computers have Linux OS. If you wish to become a Linux professional in a reputed organization, then this is the right platform to prepare for your job interview. In this Linux Interview Questions blog, you will cover some of the most common interview questions asked during interviews in this domain. Let’s get a quick look at these frequently asked questions:

Q1. What is Linux?
Q2. Compare Linux with Windows.
Q3. What are the components of the Linux system?
Q4. What is LILO?
Q5. Suppose, you wish to print a file ‘draft’ with 60 lines on a page. What command would you use?
Q6. What is LD_LIBRARY_PATH?
Q7. Name a service that you should disable (which acts both as web and FTP servers) on a Linux server.
Q8. What does sar provide? Where are the sar logs stored?
Q9. How to check memory stats and CPU stats as a Linux Admin?
Q10. How to reduce or shrink the size of the LVM partition?

We have categorized the Linux interview questions and answers into three parts as mentioned below:
1. Basic

2. Intermediate

3. Advanced

Watch this Linux Interview Questions And Answers Video on YouTube:

Top 50 Linux Interview Questions and Answers

Youtube subscribe

Basic Linux Interview Questions for Freshers

1. What is Linux?

Linux is an open-source operating system based on UNIX. It was named after the founder “Linus Torvalds”. He introduced Linux with the primary goal to offer an operating system at a free or very reasonable price for users. It is based on the Linux kernel and is compatible with different hardware platforms such as Intel, MIPS, HP, IBM, SPARC, and Motorola hardware platforms. Linux’s mascot, a penguin named Tux, is another popular feature. Linux offers a user-friendly environment where they can easily modify and create variations in the source code.

2. Compare Linux with Windows.

Criteria Linux Windows
Type of OS Open-source Proprietary
Customization High level of customization Cannot be changed
Security Excellent Vulnerable to security issues

3. What are the components of the Linux system?

There are three primary components of the Linux system which are explained below.

Kernel: The kernel is the most important component of Linux. It is in charge of the operating system’s primary functions. It is made up of a number of modules that interface directly with the hardware. Kernel offers the necessary abstraction for system or application programs to mask low-level hardware information.

System libraries: They are specialized functions or programs that allow application programs or system utilities to access Kernel capabilities. These libraries implement the majority of the operating system’s functionality and do not require kernel module code access permissions.

System Utility: Programs in the System Utility category are in charge of performing specialized, individual-level activities. They are more dependable and also provide users control over the computer.

4. What is LILO?

LILO (Linux Loader) is a boot loader for Linux. It is used to load Linux into memory and start the operating system. LILO can be configured to boot other operating systems as well. LILO is customizable, i.e., if the default configuration is not correct, it can be changed. The config file for LILO is lilo.conf. LILO is also a code snippet that loads PC BIOS into the main memory at the time of starting the computer system.

It handles the following tasks:

  • Locating Linux kernel
  • Identifying other supporting programs and loading them in memory
  • Starting the kernel

The selection of various Kernel images and boot routines is supported by LILO. For this reason, it is known as the boot manager.

5. Suppose, you wish to print a file ‘draft’ with 60 lines on a page. What command would you use?

The command used for this purpose would be as follows:

pr -l60 draft

Note: The default page length when using pr is 66 lines. The -l option specifies a different length.

Get 50% Hike!

Master Most in Demand Skills Now !

6. What is LD_LIBRARY_PATH?

LD_LIBRARY_PATH is an environment variable used for debugging a new library or a non-standard library. It is also used to identify the directories that need to be searched for; in order to do this, the path to search for the directories needs to be specified.

The variable can be set using the following:

setenv—LD_LIBRARY_PATH--$PATH

It is used to search for the shared objects/dynamic libraries by the operating system for extendable functionality at the runtime.

Prepare yourself for the Linux certification with this comprehensive Linux Training in London!

7. Name a service that you should disable (which acts both as web and FTP servers) on a Linux server.

The finger service should be disabled on a Linux server because a remote user can get important information about the system by using this command.

8. What does sar provide? Where are the sar logs stored?

In Linux, the sar command collects, reports, or saves system activity information, and it serves to log and evaluate a variety of information regarding system activity. With performance problems, sar also permits retroactive analysis of the load values for various sub-systems (CPUs, memory, disks, interrupts, network interfaces, and so on). If CPU utilization is near to 100 percent, the sampled workload is considered to be CPU-bound.

By default, the log files of the sar command are located at the /var/log/sa/sadd file, where the dd parameter indicates the current day.

9. How to check memory stats and CPU stats as a Linux Admin?

Using the free and vmstat commands, we can display the physical and virtual memory statistics, respectively. With the help of the sar command, we can see the CPU utilization and other stats.

Memory Stats

Enroll in our Linux Training to get a clear understanding of the Linux concepts!

10. How to reduce or shrink the size of the LVM partition?

Below are the logical steps to reduce the size of the LVM partition:

  • Unmount the file system using the unmount command
  • Use the resize2fs command as follows:
resize2fs /dev/mapper/myvg-mylv 10G
  • Then, use the lvreduce command as follows:
lvreduce -L 10G /dev/mapper/myvg-mylv

This way, we can reduce the size of the LVM partition and fix the size of the file system to 10 GB.

11. What are the different modes of Network Bonding in Linux?

Below is the list of various modes used in Network Bonding:

  • balance-rr or 0: The round-robin mode for fault tolerance and load balancing
  • active-backup or 1: Sets the active-backup mode for fault tolerance
  • balance-xor or 2: Sets an XOR (exclusive-or) mode for fault tolerance and load balancing
  • broadcast or 3: Sets a broadcast mode for fault tolerance. All transmissions are sent on all the slave interfaces
  • 802.3ad or 4: Sets an IEEE 802.3ad dynamic link aggregation mode and creates aggregation groups that share the same speed and duplex settings
  • balance-tlb or 5: Sets a transmit load balancing (TLB) mode for fault tolerance and load balancing
  • balance-alb or 6: Sets an active load balancing (ALB) mode for fault tolerance and load balancing

For more details, check out Intellipaat’s Linux Training in Sydney!

12. How to check and verify the status of the bond interface?

Using the following command, we can check which mode is enabled and what LAN cards are used in this bond:

cat /proc/net/bonding/bond0

In this example, we have a single bond interface. However, we can have multiple bond interfaces like bond1, bond2, and so on.

Career Transition

13. Do you know the Maximum length (in bytes) of the filename in Linux?

The maximum length of a filename is 255 bytes. In this filename, the pathname is not included, so the total length of the pathname and filename may easily surpass 255 characters.

14. What are the two different kinds of Linux User Modes?

The following are the two types of Linux user modes:

  • Command Line
  • GUI

15. What is Hard Link?

In Linux, Hard links can be defined as another name for an already existing file. For each file, we can generate an unlimited number of hard links. They have the ability to generate links for other hard connections. We can use the “ls -l” command to find out the total number of hard links in a file. And we can create Hard links using the following command:

$ ln [original filename] [link name]

16. What is Soft Link?

Soft link is also known as symbolic link. Soft links are files that, in most cases, lead to another file. It just links to another entry somewhere in the file system and does not include any data in the destination file. These kinds of connections can be utilized across several file systems. The following command can be used to create soft links:

$ ln -s [original filename] [link name]

CTA

Check out this video on Linux Shell Tutorial:

Top 50 Linux Interview Questions and Answers

Youtube subscribe

Intermediate Linux Interview Questions

17. Explain the features of the Linux system?

The key features of the Linux system are as follows:

  • Linux is a community-based major project which is freely available open-source code. Multiple teams collaborate to improve the capabilities of this operating system, which is always growing.
  • It offers a prominent feature which is that it is a multiuser system, which implies that several users may share system resources such as memory, ram, and application programs.
  • Portability refers to the capacity of software to run on a variety of hardware platforms in the same way. The Linux kernel and application software may be installed on virtually any hardware platform.
  • Linux is a multiprogramming system, which means it can run many programs at the same time.
  • Linux has a Hierarchical File System (HFS), which offers a standardized structure for storing system and user data files.
  • Linux contains a custom interpreter application that allows users to run operating system program commands and instructions.
  • User security is provided by Linux through authentication mechanisms such as password protection, limited access to particular files, and data encryption.

18. Why is Linux regarded as a more secure operating system than other operating systems?

Linux has become more popular in the technology industry in terms of security. There are several reasons why Linux is more secure than other operating systems.

  • On Linux, only a few people have access to the system. As a result, the virus cannot infect the entire system but it may affect only a few files.
  • Before opening the files, Linux users must first complete the tasks, so that they can protect their systems against flaws.
  • The Linux operating system includes a variety of working environments, including Linux Mint, Debian, Arch, and others, all of which include virus protection.
  • It keeps a log history so that it may quickly see the specifics of the system files afterward.
  • Iptables is a Linux feature that examines the system’s security circle.
  • As Linux users are comparatively less in number as compared to other operating systems, security will be enhanced.

19. How can you enhance the security of the password file in Linux?

It is in the test file named ‘/etc/passwd’ that Linux usually keeps its user account details, including the one-way encrypted passwords. However, this file can be accessed with the help of different tools, which might throw security issues.

To minimize this risk, we will make use of the shadow password format that saves the account details in a regular file /etc/passwd as in the traditional method but with the password stored as a single ‘x’ character, i.e., it is not the original password that is actually stored in this file. Meanwhile, a second file /etc/shadow will have the encrypted password, along with the other relevant information, such as the account/password expiration date, etc. Most importantly, the latter file is readable only by the root account, and thus it minimizes the security risk.

20. What are the three standard streams in Linux?

In Linux, standard streams are channel communication of input and output between a program and its environment. In the Linux system, input and output are spread among three standard streams which are:

  1. Standard Input (stdin)
  2. Standard Output (stdout)
  3. Standard Error (stderr)

21. What command can you use to make a tape archive file of /home directory and send it to the /dev/tape device?

The command used here is:

tar -cvf /dev/tape /home

The -xvf option is used to extract files from an archive.

Expert Linux professionals are in high demand. Take this Linux Course in Toronto and join the big league!

22. What is CLI?

The acronym CLI stands for Command Line Interface. The user can input declarative instructions into this interface to direct the machine tasks. It communicates with a software program by issuing commands in the form of text lines. It also interacts with computer terminals; the interface receives text lines and transforms them into operating system commands. CLI offers great flexibility.

23. What is GUI?

A GUI (Graphical User Interface) is a type of interface between humans and machines that allows people to interact with electronic devices via graphical icons and visual indications. The inclusion of graphical components makes it easier to interact with the system, as well as provides additional appeal through images, icons, and colors, rather than having to memorize and write commands. Users will find it simpler to engage with the system if certain graphical components or icons are used. It is visually appealing and enables increased productivity.

24. Suppose, your FTP Server is hacked and the entire server needs to be restored. How would you restore the original kernel system files?

We cannot restore the entire operating system from the tape backup device. Therefore, we should reinstall the core operating system and then restore the system configuration files and user data from the tape backup device.

25. Why should you avoid Telnet to administer a Linux system remotely?

Telnet uses the most insecure method for communication. It sends data across the network in plain text format, and anybody can easily find out the password using the network tool.

Telnet

It includes the passing of the login credentials in plain text, i.e., anyone running a sniffer on the network can find the information he/she needs to take control of the device in a few seconds by eavesdropping on a Telnet login session.

26. Differentiate between Linux and Unix

The differences between Linux and Unix are mentioned in the following table:

Linux Unix
Offers both paid and free OS Cost varies with the levels
It is portable It is non-portable
The installation process of Linux does not involve any hardware components Hardware components are needed to install Unix
It is developed by a worldwide Linux community. It is developed by AT&T developers.
It is highly flexible and compatible It is less flexible and compatible compared to Linux. 
It is used in both software and hardware, frameworks, etc.  It is used in servers, workstations, etc.

27. Name the four Configuration Management Tools used in UNIX-like operating systems.

  • Ansible
  • Chef
  • Puppet
  • CFEngine

Certification in Full Stack Web Development

28. Mention the difference between BASH and DOS

The key differences between BASH and DOS are given below:

BASH DOS
Bourne Again Shell Disk Operating System
Case Sensitive commands Non Case sensitive commands
/ represents directory separator / represents command argument
\ represents escape character \ represents directory separator 
Follows conventional naming Does not follow conventional naming

29. What is the difference between Cron and Anacron?

There are many differences between Cron and Anacron as given below:

  • Minimum granularity with Cron is in minutes, while it is in days with Anacron.
  • A Cron job can be scheduled by any normal user, while Anacron can be scheduled only by a superuser (a superuser is a special user account used for system administration. Depending on the operating system, the actual name of this account might be root, administrator, admin, or supervisor).
  • Cron expects the system to be up and running, while Anacron doesn’t expect this all the time. In the case of Anacron, if a job is scheduled and the system is down at this time, it will execute the job as soon as the system is up and running.
  • Cron is ideal for servers, while Anacron is ideal for both desktops and laptops.
  • Cron should be used when we want a job to be executed at a particular hour and minute, while Anacron should be used when the job can be executed at any time.

30. Explain various file permissions in Linux?

In Linux, each file and directory has three categories of owners which are User, Group, and Others. For all three owners, there are three sorts of permissions defined as mentioned below:

Read: This read permission allows you to open the file, read it and list the content of the directory.

Write: This permission gives you the ability to change the contents of a file as well as add, remove, and rename files in directories.

Execute: The file in the directory can be accessed and run by the user. The execute permission must be established before a file may be run.

31. Which command is used to check the number of files, disk space, and each user’s defined quota?

The repquota command is used to check the status of a user’s defined quota, along with the disk space and the number of files used.

repquota

This command gives a summary of the user’s quota, i.e., how much space and files are left for the particular user. Each user has a defined quota in Linux. This is done mainly for security as it restricts files from unwanted access. The quota can be given to a single user or to a group of users.

32. What is the name and path of the main system log?

By default, the main system log is /var/log/messages. This file contains all messages and scripts written by a user. By default, all scripts are saved in this file. This is the standard system log file, which contains messages from all system software, non-kernel boot issues, and messages that go to dmesg. The dmesg file is a system file that is written upon the system boot.

Want to be Linux Certified? Learn about Linux Certification!

33. Can we convert a Linux computer into a router in order to enable multiple machines to work on the same Internet connection? If yes, how?

Yes! We can convert a Linux PC into a router so that it can act as an IP gateway for a network. This process of turning a Linux machine to a router is referred to as IP Masquerade, which is basically a Linux networking function that is quite similar to the one-to-many network address translation servers.

Linux IP Masquerading enables the other ‘internal’ computers that are linked to this Linux system to get connected to the Internet. This Linux feature is available even when these machines do not have their own IP addresses.

In Linux, we can perform IP Masquerading by following the below steps:

Step 1: First of all, we have to make sure that our Linux PC is having an Internet connection, along with a LAN connection. In fact, a Linux PC will be having a PPP connection and an Ethernet card.
Step 2: As the default gateway for TCP/IP networking, all the other systems on our LAN use the Linux machine. Hence, we have to use the same DNS addresses provided by the Internet service provider on all our systems.
Step 3: Now, for enabling IP forwarding, we will use the following command:

echo 1 > /proc/sys/net/ipv4/ip_forward

For checking whether we have IP forwarding enabled already, we can use the following:

sysctl net.ipv4.ip_forward
net.ipv4.ip_forward = 0

Or, we will just check out the value i /proc/sys/net/ipv4/ip_forward:

~]# cat /proc/sys/net/ipv4/ip_forward
0

Step 4: Finally, we will run /sbin/iptables for setting up those rules that enable IP Masquerading.

Become a Full Stack Web Developer

34. What are the different types of modes in VI editor?

The VI editor (Visual Editor) is a basic text editor that appears in most Linux distributions. The following are the main varieties of modes usable in the VI editor:

Command Mode/Regular Mode: The default mode for vi editors is Command Mode/Regular Mode. It is typically used to view and write instructions that perform special or unique vi tasks. 

Insertion Mode/Edit Mode: You may use this Insertion mode to edit text or insert text into a file. You can also delete the text. 

Ex Mode/Replacement Mode: Ex mode is commonly used for file saving and command execution. We can overwrite the text in this mode.

35. In Linux, how would you change the window manager?

The /.xinitrc file lets us change the window manager that we will use while logging into the X window session. The dot (.) here tells us that this particular file is a hidden. It also means that this file will not be present when we carry out a normal directory listing. In order to set up a window manager, the following command should be saved in this file:

exec window manager

Once we are done with this part, the next step is to save the file. This way, a new window manager opens up every time we run a startx, and it becomes the default.

Now, let’s check out the commands used for starting some very common desktop environments and window managers:

  • KDE = startkde
  • GNOME = gnome-session
  • BlackBox = blackbox
  • FVWM = fvwm
  • Window Maker = wmaker
  • IceWM = icewm

Advanced Linux Interview Questions and Answers for Experienced Professionals

36. Mention various Linux directory commands

There are five fundamental Linux directory commands for working with files and directories, as listed below:

  • pwd:  pwd refers to “print working directory”. We use this command for displaying the path of the current working directory. The syntax of this command is $ pwd 
  • cd: cd refers to “change directory”. We use this command for changing the present working directory to the specifically required directory. The syntax of this command is $ cd <path to new directory> 
  • Is: ls refers to “list”. We use this command to view the full list of content of files and directories in the present working directory. The syntax of this command is $ ls 
  • mkdir: mkdir refers to “make directory”. We use this command for creating directories in Linux.  The syntax of this command is $ mkdir <name (and path if required) of new directory>
  • rmdir: rmdir refers to “remove directory”. We use this command for removing or deleting any directory on the command line. The syntax of this command is $ rmdir <name (and path if required) of directory>

37. How are shadow passwords given in Linux?

In Linux, the pwconv command is used for providing the shadow passwords. Shadow passwords are given for better system security. This command creates the file /etc/shadow and changes all passwords to ‘x’ in the /etc/passwd file.

First, the entries in the shadowed file, which don’t exist in the main file, are removed. Then, the shadowed entries that don’t have ‘x’ as the password in the main file are updated. Any missing shadowed entries are also added. Finally, passwords in the main file are replaced with ‘x’. These programs can be used for initial conversion as well to update the shadowed file if the main file is edited by hand.

Get certified from the top Linux Course in Singapore now!

38. List out some Linux distributors?

We have a lot of Linux distributors, so we’ll go through a few of the more significant ones. 

  • Linux Mint: It is a stable and reliable operating system. Mate desktop and cinnamon are used in Linux Mint.
  • Debian: It is a Linux distribution that stands for stability, reliability, and a well-oiled release process.
  • Manjaro: It provides a pleasurable experience for both novice and seasoned users.
  • Ubuntu: Ubuntu is based on Debian and is available in desktop and server variants.
  • openSUSE: It is a fantastic choice for both novice and experienced users.

39. What daemon is used for scheduling commands?

The crontab command is used for scheduling commands to run at a later time.

Syntax:

crontab [ -u user ] file
crontab [ -u user ] { -l | -r | -e }

Options:

  • -l: Displays the current crontab entries
  • -r: Removes the current crontab
  • -e: Edits the current crontab using the editor specified by the VISUAL or EDITOR environment variables

crontab

When a user exits from the editor, the modified crontab will be installed automatically. Each user can have their own crontab and though these are files in /var, they are not intended to be edited directly.

If the -u option is given, then the crontab gives the name of the user whose crontab is to be tweaked. If it is given without this option, then it will display the crontab of the user who is executing the command.

40. What do you know about Linux Shell and its types?

The Linux shell is software that serves as a user interface between the user and the kernel. By writing programs, instructions, and scripts on the shell, users may execute instructions and communicate with the kernel. The Linux shell is software that allows users to run commands. It takes human-readable commands as input and translates them into kernel-friendly language.

The main five types of shells in Linux are:

  • CSH (C Shell)
  • BASH (Bourne Again Shell)
  • KSH (Korn Shell)
  • TCSH (Tenex C Shell)
  • ZSH(Z Shell)

41. What shell does a Linux Administrator assign to a POP3 mail-only account?

A Linux Administrator assigns a POP3 mail-only account to the /bin/false shell. However, assigning a bash shell to a POP3 mail-only account gives the user the login access, which is usually avoided. The /bin/nologin shell can also be used. This shell is provided to the user when we don’t want to give shell access to the user. The user cannot access the shell, and it rejects shell login on the server as in Telnet. It is mainly meant for the security of the shells.
POP3 is basically used for downloading mail-to-mail programs. So for the illegal downloading of emails on the shell, this account is assigned to the /bin/false shell or the /bin/nologin shell. Both shells are the same as they do the same work of rejecting the user login to the shell.
The main difference between these two shells is that the false shell shows the incorrect code and any unusual coding when a user logs in to it, whereas the nologin shell simply tells us that no such account is available. Therefore, the nologin shell is used often in Linux.

42. If a volume group named VG0 already exists and we need to extend this volume group up to 4 GB, how do we do it?

  • First, we would create a physical volume (/dev/sda7) of size 4 GB.
  • Then, we would run the following command:
vgextend VG0 /dev/sda7

43. Is there any relation between the modprobe.conf file and network devices?

Yes, this file assigns a kernel module to each network device.

Example:

[[email protected] ~]# cat /etc/modprobe.conf
alias eth0 b44
Here, b44 is the kernel module for network device eth0.
We can confirm whether this module “b44” is present or not by the following command
[[email protected] ~]# lsmod |grep b44
b44 29005 0

44. What is YUM?

YUM stands for Yellow dog Updater, Modified because it is based on YUP, the Yellow dog Updater. Yellow Dog is a version of Linux for the Power Architecture hardware and is RPM-based, just like Red Hat Enterprise Linux and Fedora. YUP, and later YUM, were written by the Linux community as a way to maintain an RPM-based system.

45. What is the role of Kudzu?

Kudzu is used to detect new hardware. Red Hat Linux runs a hardware discoverer, called Kudzu. When attempting to identify a serial port, Kudzu resets the serial port. This stops the serial console. Kudzu is configured from the following file:

/etc/sysconfig/kudzu

Kudzu can be prevented from resetting hardware, by setting the configuration parameter SAFE to ‘yes.’

46. What is the difference between ext2 and ext3 file systems?

  • The ext3 file system is an enhanced version of the ext2 file system.
  • The most important difference between ext2 and ext3 is that ext3 supports journaling.
  • After an unexpected power failure or system crash (also called an unclean system shutdown), each ext2 file system must be checked for consistency by the e2fsck program. This is a time-consuming process and during this time, any data on the volumes is unreachable.
  • The journaling provided by the ext3 file system means that this sort of a file system check is no longer necessary after an unclean system shutdown. The only time a consistency check occurs while using ext3 is in certain rare hardware failure cases, such as hard drive failures. The time to recover an ext3 file system after an unclean system shutdown does not depend on the size of the file system or on the number of files. Rather, it depends on the size of the journal used to maintain consistency. The default journal size takes almost a second to recover, depending on the speed of the hardware.

47. Explain the /proc file system?

The /proc file system is a virtual file system that provides detailed information about Linux Kernel, hardware, and running processes. Files under the /proc directory are named as virtual files.

proc file system

Since /proc contains virtual files, it is called a virtual file system. These virtual files have unique qualities. Most of them are listed as zero bytes in size. Virtual files such as /proc/interrupts, /proc/meminfo, /proc/mounts, and /proc/partitions provide an up-to-the-moment glimpse of the system’s hardware. Others, such as the /proc/filesystems file and the /proc/sys/ directory, provide system configuration information and interfaces.

48. In Linux, how can I figure out where a file is stored?

To find the path to the file, use the locate command. If you wish to locate the locations of a file named sample.txt, use the following command:

$ locate sample.txt

49. How would you create an ext4 file system?

We can create an ext4 file system with the following command:

# mke2fs -t ext4 /dev/DEV

50. In Linux, how do you stop a running process?

Every process has its own identifier. We must first locate the process id in order to terminate it. The “ps” command displays a list of all currently active processes, along with their ids. The “kill” command is then used to end the process.

51. How to enable ACLs for the /home partition?

Add the following entry in /etc/fstab:

LABEL=/home /home ext3 acl 1 2

Then, remount the /home partition with the acl option:

mount -t ext3 -o acl /dev/sda3 /home

To understand Linux concepts better, sign up for our Linux Course today!

Course Schedule

Name Date
Python Course 2021-09-18 2021-09-19
(Sat-Sun) Weekend batch
View Details
Python Course 2021-09-25 2021-09-26
(Sat-Sun) Weekend batch
View Details
Python Course 2021-10-02 2021-10-03
(Sat-Sun) Weekend batch
View Details

4 thoughts on “Top 50 Linux Interview Questions and Answers”

Leave a Reply

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