Browse by Domains

Top 20 Linux Interview Questions and Answers 2024

Table of contents

Linux is one of the best operating system available in the market. This blog will be helpful for all aspiring Linux engineers and experienced system engineers who are looking out for Linux interview questions. This article also includes all the basic to advanced questions being asked in the interviews.

Let us start with frequently asked Linux interview questions in the interviews:-

  1. How to remove file and directories?

rm  file1 file2

rmdir dir1 (only deletes empty directories)

rm –r dir1 dir2

  1.  How to change from one directory to other?

cd dir1

  1. How to find logs older than seven days and remove them?

find /path/ -type f -mtime +7 -name ‘*.gz’ -execdir rm — ‘{}’ \;

Details:

find: the UNIX command for finding files/directories/links etc.

/path/: the directory path where you are searching for old logs

-type f: specifying to check only for files.

-name ‘*.gz’: will find for the files that end with “.gz”.

-mtime +7: only consider the ones with modification time older than 7 days.

-execdir … \;: for each such result found, execute the following command.

rm — ‘{}’: remove the file; the {} part is where the output from previous command will be given as input.

  1. What is cron job and how to set it?

cron is a kind of a daemon that executes scripts or programs at specific time intervals.

These commands are called cron jobs.

This is like a scheduler for system admins and developers. Many use cases are present for which we can set cron jobs like log rotation,

emailing users to trigger any update for automatic data backup at any specified timings.

find the standard cron job writing style:- 

* * * * * script1

please find the details below for all the description for every *:-

# +—————- minute (0 – 59)

# |  +————- hour (0 – 23)

# |  |  +———- day of month (1 – 31)

# |  |  |  +——- month (1 – 12)

# |  |  |  |  +—- day of week (0 – 6) (Sunday=0)

# |  |  |  |  |

  *  *  *  *  *  command to be executed

if you want to save the output of the cron job, you can execute the below command.

Timing   Execute Path to script                   Output

* * * * * /usr/bin/scripts /var/www/html/crontest/cron.sh > /dev/null 2>&1

  1. How to copy the files in Linux?

cp command

we can use cp command to copy any data from the current directory to a different directory. 

For example:-the command cp test.txt /home/users/files would create a copy of test.txt at “/home/users/files”

  1. How to move the files in Linux?

mv command

mv command can be used to move files from one folder to another; This is also used to rename the files.

This works as cp command only. We need to type mv, the file’s name, and the destination’s directory. 

For example: mv file.txt /home/users/Docs.

  1. What is sudo command?

sudo stands for “SuperUser Do”, this command enables you to perform tasks that require administrative or root permissions. 

However, it is not recommended to use sudo command because most of the tasks would be performed as a particular user.

  1. Which command is used to check disk space and disk usage?

df command

df command is used to check the disk space, shown in percentage and KBs. 

If you want to see the report in megabytes, type df -m.

du command

this is used to check Disk Usage. 

However, the disk usage summary will show disk block numbers instead of the usual size format. 

If you want to see it in bytes, kilobytes, and megabytes, add the -h argument to the command line.

  1. How to check first few and last few lines of any linux file?

The head command is used to view the first lines of any text file. By default, it will show the first ten lines, 

but you can change this number to your liking. 

For example, if you only want to show the first five lines.

head -n 5 filename.ext.

tail command

This one has a similar function to the head command, but instead of showing the first lines, 

the tail command will display the last ten lines of a text file. 

tail -n filename.ext.

10. How to check the difference between two Linux files?

diff command

the diff command compares the contents of two files line by line. 

After analyzing the files, it will output the lines that do not match. 

Programmers often use this command when they need to make program alterations instead of rewriting the entire source code.The simplest form of this command

       diff file1.ext file2.ext

11  Which command is used to archive files in Linux?

The tar command is the most used command to archive multiple files into a tarball — a common Linux file format that is similar to zip format, 

with compression being optional.

12 How to kill a process?

If a process becomes unresponsive and you wish to kill that process. Get the pid of that process and kill using the below command.

Kill Sign option file1

Kill -9 file   ( 9 forces programs to stop immediately)

you also need to know the process identification number (PID) of the program you want to kill. If you don’t know the PID, simply run the command ps ux.

13 How to check connectivity of any linux  server?

Use the ping command to check your connectivity status to a server. 

For example, by simply entering ping example.com, 

the command will check whether you’re able to connect to the server and measure the response time.

14 How to download the file using CLI?

wget command is used to download the files from the internet.

15 How to check the OS version in Linux?

The “uname” command, short for Unix Name, will print detailed information about your Linux system like the machine name, operating system, kernel etc.

16 how to add new user and delete user in linux?

useradd and userdel are used to add and delete users respectively.

 useradd tom

userdel tom

17. What is shell script?

Shell script is a program which includes a list of commands which are given in order for execution.

18 What is LVM Striping?

LVM Striping is a feature which helps us to write data on multiple disks, instead of constant write on a single Physical volume.

Advantages of Striping:

It will increase the performance of disk.

Saves from hard write over and over to a single disk.

Disk fill-up can be reduced using striping over multiple disks.

In Logical volume management, if we need to create a logical volume the extension will get fully mapped to the volume group and physical volumes. 

In such a situation if one of the PV (Physical Volume) gets filled we need to add more extends from other physical volume. 

Assume we have four disks drives and pointed to four physical volumes.

If each physical volume is capable of 100 I/O totally our volume group will get 400 I/O.

If we are not using the stripe method, the file system will write across the underlying physical volume. 

For example, some data writes to physical volume 100 I/O will be written only to the first (sdb1) PV. 

If we create the logical volume with a stripe option while writing, it will write to every four drives by splitting 100 I/O, that means every four drives will receive 25 I/O each.

This will be done in a round robin process. If any one of the logical volume need to be extended,

In this situation, we cannot add 1 or 2 PV. We have to add all 4 pvs to extend the logical volume size. 

This is one of the drawbacks of the stripe feature, from this we can know that while creating logical volumes we need to assign the same stripe size overall logical volumes.

Logical Volume management has these features that we can stripe the data over multiple pvs simultaneously. 

If you are familiar with logical volume, you can go ahead to set up the logical volume stripe. If not, you must need to know about the logical volume management basics; read below articles to know more about logical volume management.

19 What is RAID level ?

RAID is traditionally implemented in businesses and organizations where disk fault tolerance and optimized performance are taken care. 

Servers in business data centers typically have a RAID controller—a piece of hardware that controls the array of disks.

These systems feature multiple SSD or SATA drives, depending on the RAID configuration. Because of the increased storage demands of consumers, home NAS devices also support RAID. Home, prosumer, 

and small business NASes are increasingly shipping with two or more disk drive bays so that users can leverage the power of RAID just like an enterprise can.

Software RAID means you can setup RAID without need for a dedicated hardware RAID controller. 

The RAID capability is inherent in the operating system. 

Windows 8’s Storage Spaces feature and Windows 7 (Pro and Ultimate editions) have built-in support for RAID. 

You can set up a single disk with two partitions: one to boot from and the other for data storage and have the data partition mirrored.

20 Explain types of RAID level in Linux?

Types of RAID:-

RAID 0 is used to increase server’s performance. 

It’s also known as “disk striping.” With RAID 0, data is written across multiple disks. 

This means the operations that the system is doing is handled by multiple disks rather than just one, 

increasing performance because multiple drives are reading and writing data, improving disk I/O. 

A minimum of two disks is required. Both software and hardware RAID support RAID 0, as do most controllers. 

The downside is that there is no fault tolerance. If one disk fails, then that affects the entire array and the chances for data loss or corruption increases.

RAID 1 is a fault-tolerance configuration known as “disk mirroring.” 

With RAID 1, data is copied seamlessly and simultaneously, from one disk to another, creating a replica, or mirror. 

If one disk gets fried, the other can keep working. It’s the simplest way to implement fault tolerance and it’s relatively low cost.

The downside is that RAID 1 causes a slight drag on performance. 

RAID 1 can be implemented through either software or hardware. 

A minimum of two disks is required for RAID 1 hardware implementations. 

With software RAID 1, instead of two physical disks, data can be mirrored between volumes on a single disk. 

One additional point to remember is that RAID 1 cuts total disk capacity in half: 

If a server with two 1TB drives is configured with RAID 1, then total storage capacity will be 1TB not 2TB.

RAID 5 is by far the most common RAID configuration for business servers and enterprise NAS devices. 

This RAID level provides better performance than mirroring as well as fault tolerance. 

With RAID 5, data and parity (which is additional data used for recovery) are striped across three or more disks. 

If a disk gets an error or starts to fail, data is recreated from this distributed data and parity block— seamlessly and automatically. 

Essentially, the system is still operational even when one disk kicks the bucket and until you can replace the failed drive. 

Another benefit of RAID 5 is that it allows many NAS and server drives to be “hot-swappable” meaning in case a drive in the array fails, 

that drive can be swapped with a new drive without shutting down the server or NAS and without having to interrupt users who may be accessing the server or NAS. 

It’s a great solution for fault tolerance because as drives fail (and they eventually will), the data can be rebuilt to new disks as failing disks are replaced. The downside to RAID 5 is the performance hit to servers that perform a lot of write operations. For example, with RAID 5 on a server that has a database that many employees access in a workday, there could be noticeable lag.

RAID 6 is also used frequently in enterprises. 

It’s identical to RAID 5, except it’s an even more robust solution because it uses one more parity block than RAID 5. 

You can have two disks die and still have a system be operational.

RAID 10 is a combination of RAID 1 and RAID 0 and is often denoted as RAID 1+0. 

It combines the mirroring of RAID 1 with the striping of RAID 0. 

The RAID level gives the best performance, but it is also costly, requiring twice as many disks as other RAID levels for a minimum of four. 

This is the RAID level ideal for highly utilized database servers or any server that’s performing many write operations. 

RAID 10 can be implemented as hardware or software, but the general consensus is that many of the performance advantages are lost when you use software RAID 10.

Other RAID Levels There are other RAID levels: 2, 3, 4, 7, 0+1…

but they are really variants of the main RAID configurations already mentioned, and they’re used for specific cases. Here are some short descriptions of each:

RAID 2 is similar to RAID 5, but instead of disk striping using parity, striping occurs at the bit-level. 

RAID 2 is seldom deployed because costs to implement are usually prohibitive (a typical setup requires 10 disks) and gives poor performance with some disk I/O operations.

RAID 3 is also similar to RAID 5, except this solution requires a dedicated parity drive. 

RAID 3 is seldom used except in the most specialized database or processing environments, which can benefit from it.

RAID 4 is a configuration in which disk striping happens at the byte level, rather than at the bit-level as in RAID 3.

RAID 7 is a proprietary level of RAID owned by the now-defunct Storage Computer Corporation.

RAID 0+1 is often interchanged for RAID 10 (which is RAID 1+0), but the two are not the same. 

RAID 0+1 is a mirrored array with segments that are RAID 0 arrays. 

It’s implemented in specific infrastructures requiring high performance but not a high level of scalability.

Avatar photo
Great Learning Team
Great Learning's Blog covers the latest developments and innovations in technology that can be leveraged to build rewarding careers. You'll find career guides, tech tutorials and industry news to keep yourself updated with the fast-changing world of tech and business.

Leave a Comment

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

Great Learning Free Online Courses
Scroll to Top