Linux Interview Questions and Answers

FREE Online Courses: Click, Learn, Succeed, Start Now!

In this article, we will go through 70 of the most beautiful interview questions with Answers based on Linux. In this article, we are targeting slightly advanced people as we discuss many commands, options, and some technical questions too.

This article would be perfect for candidates attending job interviews as well as M. Tech and B.Tech students attending VIVA or interviews for their job placements. If at all you find this a little out of your calibre, you can go through our other two levels of interview questions before reading this.

If you ever have any doubts regarding any of the questions, you can read our articles based on that command. So pay attention, grab a snack if you need, and go through all of the 70 questions and answers. So without any further ado, let’s start!

Linux Interview Questions and Answers

Q1. What is SSH? Explain in brief

SSH is the abbreviation for Socket Shell or Secure Shell. It is a protocol that is used to connect to a remote server or system securely. It uses an SSH protocol as the data transfers between the client and the host are encrypted.

The primary role of the SSH command in Linux is to manage remote systems. Normally, this would be another Linux system. However, it could also be a router, firewall, or even a computer with a different operating system.

In a nutshell, SSH is a cryptographic network protocol used for an encrypted connection between a client and a server.

Q2. How does SSH work?

To set up an SSH connection, we need two important components, a client and a host. The host can either be a domain name, IP address, server, and more. The client uses the given host information to establish the connection. If the credential provided is verified, an encrypted connection is established.

Q3. What is symmetric encryption?

This technique of encryption generates a key for encrypting as well as decrypting. This key is distributed among the hosts and clients to create a secure connection.

Q4. What is asymmetric encryption?

Asymmetric encryption works on the principle of factoring in really large numbers. This technique generates 2 keys called the private and public keys. The private key encrypts messages, while the public key decrypts messages that are encrypted using the respective private key. This is kept with the client machine, whereas the public key is distributed to other machines. The private key must always be kept a secret. Otherwise, it will compromise the entire secure connection.

Q5. List a few file management commands and explain their role.

Below is a list of various file management commands:

a. Pwd – displaying the current working directory

b. Cd – used for navigating through the file system

c. ls – used to list the contents of the directory

d. Touch – used to create a file

e. Cat – used to view a file

f. Mv – used to move a file

g. Cp – used to copy a file

h. Mkdir – used to create a directory

i. Rmdir – used to delete a directory

j. Rm – used to delete files

k. Find – used to locate a file in the filesystem

l. Wc – used to print count information of a file

Q6. How do you list the contents of a file in a long listing?

We can list the contents of the file in a long listing by pairing the ls command with the option “-l”. By doing so, the command prints out the following information: The file type, the file permissions, the number of hard links to the file, file owner, file group, the file size, the date, time, and file name.

Q7. How do you make the cp command ask before overwriting a file?

When you use the cp command to copy the contents of a file into another existing file, it completely overwrites the contents instead of appending. If at all you are not sure if the destination file exists already and has contents you feel are important, you can make cp to prompt you to allow overwriting.

Q8. What is the fdisk command?

Fdisk is the abbreviation for “Fixed disk” or “Format disk”. The fdisk command manipulates partition tables on the hard disk for Linux-based operating systems. Fdisk is also in MSDOS, Windows, IBM OS/2, Flex OS, and many more.

Q9. What is the LSOF command?

LSOF is short for List of Open Files. This command retrieves details about various types of files opened by different running processes. This command can not only list common or regular files but it can also perform tasks like listing things like a shared library, a special file, a named pipe, a regular pipe, a character special file, and many more.

Q10. What is chroot? Explain in brief

The Chroot command changes the apparent root directory for the currently running process. In a nutshell, chroot does one thing — It runs a command with a different root directory. Chroot does not make any modifications to your disk. Nonetheless, it can make it appear that way from the POV of the processes running under it. This command runs in such a modified environment that it cannot access files outside the root directory.

Q11. What is the fsck command?

Fsck helps in checking the consistency of a file system. Fsck stands for File System Consistency Check. It checks the filesystems for errors and outstanding issues.

Q12. How does the fsck command work?

fsck is either run automatically during boot time or run manually by the system administrator. fsck can also be run by a system administrator manually if they believe there is a problem with the file system.

The fsck command works directly on the data structures stored on the disk. While unmounted, mounted read-only, or with the system in maintenance mode, the file system is usually checked.

Q13. When do you use the fsck command?

the fsck tool can check automatically during reboot, or you can run it manually anytime you want. talking with respect to scenarios, you can use the fsck command when:

1. Files in the system get corrupt

2. System fails to boot

3. SD cards and flash drives don’t work as expected.

4. run a file system check as preventive maintenance.

Q14. Why do you use chroot?

The chroot command locks away system daemons so that any security vulnerabilities in them don’t affect the rest of the system. This command is also useful as a budget container as it creates a subset of your operating system and runs apps in an isolated environment.

Q15. What is Chroot jail?

Chroot is a process that is run in such a modified environment and cannot access files outside the root directory. The modified environment is what is called a “jailed directory” or “chroot jail”. It is the same as a chroot environment.

Q16. Why do we use the lsof command?

One of the countless reasons we use the LSOF command is when a disk cannot be unmounted as it says the files are being used. However, with the help of LSOF, we can easily identify the files which are in use. With the help of LSOF, we can find the different processes like:

1. Retrieve information about opened files

2. List all files a process is locking

3. Lock up a file or directory

4. Listing a process listening on a port

5. Identify files that are in use

And many more tasks.

Q17. What is the cp command?

Cp stands for “copy” and it is a command-line-based utility that helps in copying files and directories in UNIX and Linux-based operating systems.

Q18. How does the cp command work?

The cp command creates an image of a file on a disk with a different file name. The Cp command on its own doesn’t enclose a wide variety of administration scenarios. Many other Linux commands can be combined with the CP command to make the best out of it.

Q19. What are the different operation modes of the cp commands?

The cp command has 3 principle modes. These modes are expressed by the type of arguments given to the program to copy files. These 3 modes are:

1. Copying a file to another file

2. Copying one or more files to a directory

3. Copying entire directories into a directory

Q20. What is the cat command?

The cat command stands for concatenate. It is a command-line-based utility that helps in many tasks like reading files, writing in files, viewing the content of files, concatenating files, redirecting output in the terminal and so many more things. The cat command also helps in displaying the contents of the files you want without having to open the file for editing.

Q21. What is the Dmesg command?

Dmesg is the acronym for diagnostic message. The Dmesg command is a terminal-based utility in Linux that displays kernel-related messages retrieved from the kernel ring buffer.

Q22. How does the Dmesg command work?

During a system boot-up, a number of messages are displayed on the screen where we can see hardware devices detected by a kernel. These messages are crucial for diagnosing purposes in case of a device failure

Dmesg prints the message buffer of the kernel. The output message is produced by the device drivers. The Dmesg command controls the kernel ring buffer. The diagnosing process for a failed device begins by inspecting the output of the Dmesg command from the kernel identification message till the boot process concludes

Q23. What is the traceroute command?

Traceroute allows you to investigate the routes of network packets. It also prints the path or route that the network packets take to a network host. traceroute is a network troubleshooting tool that helps us determine the number of hops a packet’s traveling path takes to reach its destination.

Q24. What are the different uses of the traceroute command?

The traceroute command helps in network troubleshooting by determining the number of hops a packet’s traveling path takes to reach its destination. It is also used to troubleshoot sluggish network connections.

The traceroute command also aids in the discovery of possible routes of information from the source to the destination as the command can map packet paths in the network.

The traceroute command is also capable of also calculating the time taken to transfer between points. This command helps you identify the limiting factor of a network packet journey and where traffic slows down between the source and destination.

Q25. How does the traceroute command work?

Traceroute works by sending packets of data to the target server, computer, or website and recording any transitional steps through which the packets travel. The output of the traceroute command will be the IP address and domain names through which the packets pass.

Q26. Explain in detail how the traceroute command works.

Upon running the traceroute command, it sends out ICMP (internet control message protocol) packets to every router transferring between the source and the destination.

traceroute acts as a series of ping commands. However, unlike the ping command, which requests a response from the destination, the traceroute also gathers intermediate information.

Q27. What information does the output of the traceroute command give?

Upon executing a traceroute command, the output displays the following:

1. IP address of the router that received the network packet

2. time it took to get a response for each of the 3 probes.

Q28. What is the LS command?

LS shows the full list of content in your present working directory. Ls is the abbreviation for List.

Q29. What is the rsync command?

The Rsync command helps in transferring and synchronizing data between different machines and directories. Rsync is the acronym for Remote sync. The Rsync command is a fast, efficient, and powerful tool as it helps in copying or transferring only the file changes from the source

Q30. What is the rsync command used for?

The Rsync command can be used with SSH (secure shell) to copy your files securely to another location. The Rsync tool also lets you copy files from your system to your remote system.

This command is most commonly used by system administrators for different tasks like data mirroring, backups, or migrating files to other systems or servers across networks and disks.

Q31. List a few advantages of the rsync command

a. The command efficiently copies files and syncs them to or from a remote system.

b. Rsync also supports the copying of links, devices, permissions, owners, and the user group.

c. Rsync is faster than SCP because it only copies the differences between the files in your system and the remote system. If you are copying the files for the first time to the remote system, it will take time as it copies the entire file, but from the next time onwards, it copies only the differences.

d. Rsync consumes less bandwidth as it uses the compression and decompression method while sending and receiving files on both ends.

Q32. What is an environment variable?

The environment variables are placeholders for information that are stored within the system that passes data to programs launched in the shells.

Environment variables define the behavior of the system’s environment, and they allow you to customize the working of the system and the behavior of the applications on the systems.

Q33. What does it mean when an environment variable has global scope?

An environment variable with global scope can be accessed from anywhere in that specific environment that exists in the terminal. The variable can be used in all kinds of programs, processes, or programs running in the environment within the terminal.

Q34. What does it mean when an environment variable has local scope?

An environment variable with a local scope cannot be accessed by any program, application, or process running in the terminal. The variable can only be accessed by the terminal itself.

Q35. What is the difference between environment and shell variables?

Variables in an operating system can be classified into two main types, shell variables, and environmental variables.

Shell variables – These are the variables that apply only to a certain shell. Each shell, like bash, Korn, bourne, zsh, etc, has its own set of internal shell variables.

Environment variables – These variables are inherited by all shield processes and shells and are available system-wide.

Q36. What are the rules you follow while creating variables in the terminal?

while creating variables in the terminal, we follow the below-listed formats

1. The names of the variables are case-sensitive. By convention, all the variables created must have upper-case names.

2. To assign multiple values to a single variable, separate the values by a colon (:).

3. You must give no space before and after the equals (=) sign.

Q37. What is the alias command?

The alias command replaces or creates an alias to a string that invokes a command. In simple words, the alias command is used to abbreviate a command in the terminal.

Alias command is also available on many other operating systems other than Linux, like AmigaDOS, Windows PowerShell, ReactOS, KolibiriOS, EFI shell, and 4DOS/4NT.

Q38. Why do we use the alias command?

The alias command is used to create a shorter abbreviation for a long command with multiple options. A typical Linux user would reuse a few sets of commands again and again, leading to copying, pasting, and typing again and again, which is such a waste of time.

Q39. What is the uname command?

The abbreviation of uname is “UNIX name”. The Uname command is a terminal-based Linux-based operating system that prints or displays information about the kernel, system architecture, operating system, hardware, version information, and more.

Q40. How do you display the process architecture of your system?

If you want to print the process architecture of your system, pair the uname command with the option “-p” or “–processor”.

Q41. What is the netstat command?

Netstat is a command-line-based tool in Linux-based operating systems that gives you a lot of information about networks. The command literally gives you a treasure chest of information that is extremely useful, like routing tables, network connection, interface statistics, multicast memberships, and so many more.

Q42. What is a socket? Explain in brief.

A socket is software used to handle one end of a network data connection. Apart from the earlier two stages, there are other states in which a socket can be the middle of connecting to a remote device.

Network sockets have two stages, either connected or waiting to be connected. These connections use networking protocols like UDP (user datagram protocol) or TCP (transport control protocol). A socket that listens is called the server, and the socket that requests the connection is the client, and with the help of the netstat command, you can see which sockets are connected, and which are listening.

Q43. What is the PWD command?

Pwd, an abbreviation for Print Working directory, sums up the command. The pwd command is slightly different from the standalone /bin/pwd executable. Upon invoking the pwd command, it does a simple job of printing the complete path of the directory you are in, starting from the root directory (/).

Q44. Explain the rm command in brief.

The acronym for rm is remove. The rm command is a terminal-based utility in Linux-based operating systems that is used to remove files and directories from your Linux filesystem from the terminal itself.

Q45. How does the rm command work?

When using the rm command, the removal process unlinks the specified file in a file system from its connected or linked data. After this, it marks that space on the storage device as “usable” by future writers.

Upon deleting a file, the data in the file does not get changed, rather it is just no longer associated with a file name. The data of the file is not erased, but after unlinking it using the rm command, it becomes inaccessible.

Q46. Can you delete a directory using the rm command? If so, how?

Yes, you can delete a directory using the rm command. If you want to delete an empty directory (a directory with no subdirectories and files), you can combine the rm command with the option “-d”.
However, the command “rm -d” does not work on non-empty directories. To delete directories that have some content in them, pair the rm command with the option “-R” to delete both the directory and the contents of it recursively.

Q47. What is the sysctl command?

The Sysctl command helps in managing the parameters and kernel configuration and other stuff like its version number, maximum limits, and security settings.

Q48. Why do we use the sysctl command?

The sysctl is extremely helpful for system administrators, because as an admin, you may need to modify the kernel’s default behaviour, increase the number of connections the kernel will accept, or enable the magic SysRq key.

Q50. What is the ping command?

Ping is the acronym for Packet Internet Groper. The Ping command helps in checking the connectivity between the hosts and the server.

Q51. How does the ping command work?

The ping command takes either the URL or IP address as the input and transfers the data packet to a specified address. During this transfer of data packets, the system also gives a ‘PING’ message. The time taken is called latency.

Q52. Why do you use the ping command?

The ping command helps you do the following:

1. checks if the remote machine is up and running.

2. tests your internet connection.

3. analyzes network issues like high latency or dropped packets.

Q53. What is the du command?

Du is the abbreviation for “Disk Usage”. The Du command helps in tracking files and directories that are consuming a lot of space on the hard disk.

Q54. What is the touch command used for?

The touch command is a command-line-based utility in Linux-based operating systems that has 2 roles:

1. Modifying a timestamp

2. Creating a file.

Q55. What are the different timestamps of a file? Explain them in brief.

In Linux-based operating systems, a file has three timestamps:

a. Atime – This timestamp stands for ‘access time’. This timestamp contains the last time the file was either accessed or opened by commands like “cat”, “vim”, “grep”, “vi”, etc.

b. Mtime – This timestamp stands for ‘modify time’. This timestamp contains the last time the contents of the file were modified.

c. ctime – This timestamp stands for change time’. This timestamp contains the last time the file’s content or attribute was changed. Attributes here mean permissions, location, or ownership.

Q56. What is the ps command?

The abbreviation for Ps is “Process Status”. The PS command is used in viewing information regarding a selection of running processes on a system.

Q57. What is the ps command used for?

The ps command shows all the currently running processes along with some extra data like PID (Process Identity), TTY, user ID, command name, how much space it occupies in the CPU, and many other things based upon the options we use.

Q58. How does the ps command work?

Upon using the ps command, it reads the process information from the “/proc” directory. Since the proc directory contains virtual files it is also called the virtual file system.

Q59. What is AWK?

Awk is a scripting language used for manipulating and generating reports. The awk language, unlike C programming, needs no compiling.
Awk is designed for advanced text processing and is mostly used as a tool for reporting and analysis.

Since awk is data-driven, you can define a set of actions to be performed against the input text. Awk takes in and transforms the input data, and sends it to stdout (standard output).

Q60. How does AWK work?

The AWK command works by scanning a set of input lines and then searches for the lines that match the pattern specified by the user.

The awk command accepts input data, which gets transformed and is sent out to the standard output. For each pattern that awk recognizes, the user can describe an action to perform on each line.

Q61. Why do we use AWK?

The AWK command is used for processing and manipulating text. It enables a programmer to write a tine program in the form of a statement where he or she can specify text patterns that are searched for in each line of a file.

Q62. What is the sed command?

SED is an abbreviation for “Stream Editor”. This command helps in editing streams. It performs numerous tasks like searching, finding, replacing, sorting, inserting, and deleting. The sed command can either be used by piping it with some other main command or simply using it on a text file.

Q63. Why do we use the sed command?

Using the sed command we can select the text, delete the line from the text, substitute text (find and replace) modify, and delete text. The best part about sed is that you don’t even have to open files to edit them (unlike vi and nano), thus making the workflow easier and more efficient. It performs different tasks like searching, finding, replacing, sorting, inserting, and deleting.

Q64. How does the sed command work?

Sed contains 2 data buffers that are both initially empty, they are pattern space and auxiliary hold space. When sed is invoked, it reads one line from the input text, (removes trailing lines if any), and stores it in the pattern space.

Then the commands are executed, and each command has an address associated with it. When the sed command reaches the end of the script, the contents of the pattern space are printed out to the output stream. And when it prints out the output, it also adds back the trailing lines which were removed earlier.

Q65. What is the df command?

Df stands for “Disk Free”. This command displays the amount of available disk space for file systems.

The df command displays a lot of important information like the number of blocks used, the number of blocks available, the directory in which the file system is mounted, and many more. By default, the df command shows the space available in the disk in 1K blocks

Q66. What is the diff command?

The Diff command helps in comparing data in files and streams. Upon comparing, it displays the difference between the two files. Unlike the cmp and comm commands, which only show the differences between the 2 files, the diff command is far more powerful as it even shows you what to change, to make both files identical.

Q67. What is the wget command?

WGET downloads files from the web. Using the wget command, you can download files using the FTP, HTTPS, and HTTP protocols.

Q68. What is the wc command?

Wc stands for “Word Count”. The WC command counts the number of characters, lines, and words in a file or data stream.

Q69. How do you count the number of files in a directory using the wc command?

We can count the number of files in a directory by piping the ls command with the wc command with the option “-l” to count the number of lines:
(ls | wc -l)

Q70. What is the curl command?

The Curl command transfers data to or from servers designed to work without user interaction. With the help of the curl command, you can either upload or download data using any supported protocols.

Summary

This is all about Linux Interview Questions and Answers. These will definitely help you clear your next interview based on linux. Hope you liked it.

Did we exceed your expectations?
If Yes, share your valuable feedback on Google

follow dataflair on YouTube

Leave a Reply

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