Linux Interview Questions and Answers Every Devops & Working Professional must know

linux interview questions and answers
Linux

In this blog post, I will be sharing a few Linux interview questions along with their answers which i faced during interview for Devops as well as Dev related roles.

For more extensive list of Interview Questions, please click here

To get a basic understanding of Linux, you can go through this tutorial

Q.) What are Inodes in linux?

In very simple terms, think of it as a unique number which is created when you create a file or a directory. Conceptually, Inodes is a data structure which stores the metadata about the file. Such as file type, permissions, file size, ownership, location of file blocks, etc. It stores everything about the file except for its name and contents

Now, you might be thinking, how does Inodes help linux kernel or why do we even need it at first place? The simple answer is, as you know Linux is made up of block file system, i.e. files are stored in the form of blocks. So, for example, if you have a 10 MB file and let’s assume, you have a block size of 1 MB each, then your file is actually stored as 10 pieces of 1 MB each. The location of these pieces is what gets stored in the inode entry of the file.

Now, every time you ask for a file, Linux kernel looks at the Dentry table (shown below), get the Inode number from it and then it goes to Inode table and gets the associated file metadata and present the file to you.

Inodes and it’s relationship to file name is what is shown in the diagram below diagram below.

inodes in linux interview questions
NOTE: Multiple files and directories can have same Inode number

Few follow up question usually asked by the interviewer could be as follows: 

Is file name stored in Inode Metadata

The simple answer is NO Dentry stores file name and inode mapping

Effect of “cp” (Copy) and “mv” (Move) commands on Inode number

cp command changes the inode number while mv command keeps the same inode number

What commands can be used to display Inode numbers

ls -i filename

stat filename

df -i

Soft Link:

Soft link is the link between files. It is more like shortcut in windows.

You delete a soft link and it does not effect the actual file or directory it is pointing to.

Inode of the linked file is different from inode of the original file.

Deleting original files makes the symlink dangling

Soft Link can link both the files as well as directories and can span across filesystems as well.

Diplayed in Console:
lrwxrwxrwx 12 12 root abc.txt->def.txt

How to create it:

ln -s <Source> <LinkName>

Hard Link:
Both hard link and the actual file share the same inode.

If source file deleted, then hard link still exists.

can not span across different filesystems

Can only link files, not directories.

How to create it:

ln <Source>  <Destination>

Q.) Important Linux commands used to troubleshoot connectivity between two servers

This question can be asked with variations link, I am not able to connect to another Linux server or how do you test connectivity to another server or DNS.

To answer the question, we will use the following commands:

  1. Ping
  2. traceroute
  3. tcpdump
  4. ensure DNS resolution is working
  5. check firewall settings

Q.) Important Linux commands used for troubleshooting server itself, i.e. how the system itself is performing

You should keep these commands handy if someone is trying to ask you about troubleshooting the server itself. For example, one might ask you how do you check what process are running, how do you check disk space

top or htop commands can show you what processes are running in your server

About the author
Kunal Choudhary

Leave a Comment

Contact About