Categories

Top 50 Linux Interview Questions and Answers

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. 

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. What are the components of the Linux system?

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.

3. 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. lilo.conf is the configuration file for LILO. 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:

1) Locating Linux kernel
2) Identifying other supporting programs and loading them in memory
3) 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.

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

The sar command in Linux is a valuable tool for collecting and analyzing system activity information. It reports various aspects of system performance, such as CPU usage, memory utilization, disk activity, network traffic, and more. When troubleshooting performance issues, sar enables you to review historical data and identify the causes of high load on specific system components.

When the CPU utilization is close to 100 percent, it indicates that the processing workload primarily demands the CPU. This information helps determine if the system is experiencing a CPU-bound situation.

By default, sar saves its log files in the /var/log/sa/sadd directory, where “dd” represents the current day. These log files are valuable for retrospective analysis and tracking system activity over time.

5. 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

6. 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

7. 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.
setenv—LD_LIBRARY_PATH--$PATH

8. 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.

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

Below are the logical ste LVM partition

1) Unmount the file system using the unmount command
2) Use the resize2fs command as follows:
resize2fs /dev/mapper/myvg-mylv 10G
lvreduce -L 10G /dev/mapper/myvg-mylv

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

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

1) balance-rr or mode 0: The round-robin mode for fault tolerance and load balancing

2) active-backup or mode 1: Sets the active-backup mode for fault tolerance

3) balance-xor or mode 2: Sets an XOR (exclusive-or) mode for fault tolerance and load balancing

4) broadcast or mode 3: Sets a broadcast mode for fault tolerance. All transmissions are sent on all the slave interfaces

5) 802.3ad or mode 4: Sets an IEEE 802.3ad dynamic link aggregation mode and creates aggregation groups that share the same speed and duplex settings

6) balance-tlb or mode 5:Sets a transmit load balancing (TLB) mode for fault tolerance and load balancing

7) balance-alb or mode 6: Sets an active load balancing (ALB) mode for fault tolerance and load balancing

11. 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

12. What is LILO?

LILO means Linux Loader is a boot loader that is used for the Linux operating system. Most of the Linux Operating systems use LILO, to boot the operating system into main memory to start the operations.

13. 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:

14. 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.

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

The following are the two types of Linux user modes:

1) Command Line
2) GUI

16. 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 `Is-I` 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]

17. What is Soft Link?

Soft link is also known as a 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

18. Explain the features of the Linux system?

1) 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.

2) 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.

3) 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.

4) Linux is a multiprogramming system, which means it can run many programs at the same time.

5) Linux has a Hierarchical File System (HFS), which offers a standardized structure for storing system and user data files.

19. 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.

1On 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.

2) Before opening the files, Linux users must first complete the tasks, so that they can protect their systems against flaws.

3) The Linux operating system includes a variety of working environments, including Linux Mint, Debian, Arch, and others, all of which include virus protection.

4) It keeps a log history so that it may quickly see the specifics of the system files afterward.

5) Iptables is a Linux feature that examines the system’s security circle.

6) As Linux users are comparatively fewer in number as compared to other operating systems, security will be enhanced.

20. 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.

21. 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)

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?

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

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.

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. Name the four Configuration Management Tools used in UNIX-like operating systems.

1) Ansible

2) Chef

3) Puppet

4) CFEngine

27. What is the difference between Cron and Anacron?

1) Minimum granularity with Cron is in minutes, while it is in days with Anacron.

2) 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).

3) 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.

3) Cron is ideal for servers, while Anacron is ideal for both desktops and laptops.

4) 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.

28. 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 <br?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.

29. 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.

30. 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 into 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.

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.

31. 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.

32. 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:

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.

1) KDE = startkde
2) GNOME = gnome-session
3) BlackBox = blackbox
4) FVWM = fvwm
5) Window Maker = wmaker
6) IceWM = icewm

33. Mention various Linux directory commands

pwd: pwd refers to “print working directory”. We use this command to display the path of the current working directory. The syntax of this command is $ pwd.

cd: cd refers to “change directory”. We use this command to change the present working directory to the specifically required directory. The syntax of this command is $ cd

Is: ls refers to “list”. We use this command to view the full list 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 to create directories in Linux. The syntax of this command is $ mkdir .

rmdir: rmdir refers to “remove directory”. We use this command to remove or delete any directory on the command line. The syntax of this command is $ rmdir .

34. 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.

35. List out some Linux distributors?

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

1) Linux Mint: It is a stable and reliable operating system. Mate and Cinnamon are two of the most popular desktop environments used in Linux Mint.

2) Debian: It is a Linux distribution that stands for stability, reliability, and a well-oiled release process.

3) Manjaro: It provides a pleasurable experience for both novice and seasoned users.

4) Ubuntu: Ubuntu is based on Debian and is available in desktop and server variants.

5) openSUSE: It is a fantastic choice for both novice and experienced users.

36. 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.

1) CSH (C Shell)
2) BASH (Bourne Again Shell)
3) KSH (Korn Shell)
4) TCSH (Tenex C Shell)
5) ZSH(Z Shell)

37. 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.

38. 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?

1) Check the available space: Use the vgdisplay command to check the available space in the VG0 volume group. Look for the “Free PE / Size” field to determine how much free space is currently available.

2) If there is not enough free space in the VG0 volume group, you may need to add physical volumes (disks) to increase the available space. This step assumes that you have additional disks available. If you already have sufficient free space,

3) Extend the logical volume: Once you have sufficient free space in the VG0 volume group, you can extend the logical volume (LV) within it. Use the lvextend command to increase the size of the LV to 4 GB.

4) Resize the file system: Finally, you need to resize the file system on the LV to utilize the newly allocated space. The specific command depends on the file system type.

39. What is YUM?

YUM stands for Yellowdog Updater Modified because it is based on YUP, the Yellowdog Updater. Yellowdog 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.

40. 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:

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

1) The ext3 file system is an enhanced version of the ext2 file system.

2) The most important difference between ext2 and ext3 is that ext3 supports journaling.

3) 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.

4)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.

42. 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:

43. 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.

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

To enable Access Control Lists (ACLs) for the /home partition, you’ll need to follow these general steps:

1) Check if ACLs are already enabled: Use the mount command to check if the /home partition is mounted with the acl option. Look for an entry that includes acl in the options field.

Backup important data: Before making any changes, it’s always a good practice to back up important data on the /home partition. This step helps ensure that you have a copy of the data in case anything goes wrong during the process.

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

[root@localhost ~]# 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
[root@localhost ~]# lsmod |grep b44
b44 29005 0

46. What daemon is used for scheduling commands?

-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 [ -u user ] file
crontab [ -u user ] { -l | -r | -e }

47. What daemon is used for scheduling commands?

-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

48. Differentiate between Linux and Unix

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.

49. Mention the difference between BASH and DOS

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

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

tar -cvf / dev/tape /home