The first 48 Linux interview questions and answers

Are you preparing for a Linux interview? We have prepared some common questions and answers for Linux interviews.

If you are a beginner (with some knowledge of Linux or have a certification) or have professional Linux management experience, please follow the “Q & A” to prepare your interview.

1. What are Linux and basic components?

Linux is a free and open source operating system based on the Linux kernel. It is one of the most widely used operating systems, especially among servers and developers. Its use extends from hosting websites and applications to being the core operating system for smart devices such as smartphones, tablets and TVs.

Linux contains 4 basic components:

core: This is the core of the Linux system. It is responsible for interacting with hardware components and ensuring that the operating system communicates with the hardware devices.

shell: Shell is the interface between Linux users and the kernel. In the shell, commands are issued by the user and then executed by the operating system.

System library: These are special programs or functions that are responsible for implementing most of the functions of the operating system without relying on the code access rights of the kernel modules.

System utilities: These are specific programs that perform certain tasks. For example LibreOffice, Brasero, Gparted.

2. What is the Linux kernel?

The Linux kernel is the core of the Linux system. It connects the underlying hardware with the operating system.

3. What is the difference between Linux and Unix?

Linux is a clone of the UNIX system. Linux is derived from Linux. Although Linux is open source and free to use, UNIX is a proprietary operating system.

4. What is the inode in Linux? How do I find the i-node associated with the file?

Inodes (inodes) are data structures in a Unix-style file system that describe file system objects (such as files or directories). When a file is created, it is assigned both a name and an inode number, which is a unique integer in the file system.


A file system usually has two parts: metadata or “data” about the data, and the data itself. Metadata contains information about the data. More precisely, it contains information such as access control lists (ACLs), file modification dates, file owner, file permissions, file size, device ID, file uid, and more. This kind of information is a file system, otherwise we only have a bunch of storage media and it doesn’t make much sense. I-nodes store this metadata information, and typically they also store information about the location of the data on the storage medium.

In the file system, the inode accounts for about 1% of the total disk space, whether it is the entire storage unit (hard disk, thumb drive, etc.) or a partition on the storage unit. I-node space is used to track files stored on the hard disk. I-node entries only point to these structures and do not store data. The size of each entry is 128 bytes. Space is allocated for the Inode during the installation of the operating system or new file system, and during initial structuring. Therefore, in this way, we can see that the maximum number of inodes is set in the file system, so the maximum number of files is set. Now, the above concept raises another interesting fact. The file system can run out of space in two ways:

  • No space left to add new data
  • All inodes are consumed.

To get a list of inode numbers, use ls -i command.

ls -li
total 3336
57741 -rw-r--r-- 1 root root 3412144 Nov 20 17:26 coreutils-8.22-18.el7.x86_64.rpm
57725 -rw-r--r-- 1 root root       0 Apr  7 04:00 file
57736 -rw-r--r-- 1 root root       0 Apr  7 04:00 new-file

# ls -li new-file 
57736 -rw-r--r-- 1 root root 0 Apr  7 04:00 new-file

# find /root -inum 57736

5. What is the Linux shell? How to check the current shell?

The Linux Shell is a command interpreter or program that accepts commands and passes them to the operating system for execution. To check the shell you are using, run the following command echo $0

6. What command is used to find memory and swap usage?

Adopt free command

Free command usage

7. What is the difference between soft and hard links?

A) Unable to create a hard link for the directory. You can only create hard links for files.

b) Symbolic links or symbolic links can link to directories.

C) Deleting the original file pointed to by the hard link does not delete the hard link itself. Hard links still provide the contents of the base file.

d) If you delete the hard link or the symbolic link itself, the original file will remain unchanged.

e) Deleting the original file does not delete the attached symbolic link or symbolic link, but the symbolic link is useless without the original file

8. Explain file permissions in Linux?

In Linux, there are mainly 3 types of file permissions: read, write, and execute. These permissions can be recursively assigned to files or directories. As a multi-user system, you can assign these permissions to root users, groups, and even other users who use the system.

Read: Read permissions are granted to the ability to open and read files.

Write: Write permissions allow users to open and modify or edit the contents of a file and save changes.

Execute: This allows users to execute or run executable files or programs or shell scripts.

Please find in the following linux permissions table:

linux permission table

9. How to create and delete directories in Linux?

To create a directory, use the mkdir command as shown below;

mkdir directory_name

For example, create a directory named ‘data’ and run the command:

mkdir data

To delete a directory in Linux, use rm Either rmdir command.

of rmdir This command is used to delete empty directories.

of rm The command is usually related to -R Flag to delete directories recursively.

10. How to create a file in Linux?

To create a file, use the touch command. For example, to create the file file1.doc, run the following command:

touch file1.doc

You can also use cat Command followed by redirection operator or greater than sign > Then the file name. Next, type the contents of the file and finally press CTRL + D Exit the file.

cat > file1.doc

Enter file content and click CTRL + D

11. How to rename files and directories in Linux?

To rename a file, use the mv command. Note that to do this, the path of the file to be renamed must be the same. For example, to rename the file file1.doc /data/files Directory to file2.doc execute the command:

mv /data/files/file1.doc /data/files/file2.doc

12. How to copy files and directories in Linux?

To copy files in Linux, use the cp command. The syntax is simple

cp  /source/of/the/file  /destination/of/the/file

13. How to list and mount devices in Linux?

To list the mount points, run the following command:

df  -aTh

To find out more about the mount points on your system, execute the following command:


Also, you can use the cat command below

cat /proc/self/mounts

Alternatively, you can use the mount command as shown below

mount -l

14. How to create an empty file in Linux?

To create an empty file in Linux, use the touch command as follows:

touch new_file

15. How do I schedule tasks in Linux? What is crontab and describes the fields in crontab?

cron is a daemon that executes commands at a specific date and time in Linux. You can use it to schedule events, either as a one-time event or as a repetitive task. Crontab is a program for installing, uninstalling, or listing tables used to drive cron daemons in a server. Each user can have their own crontab, and although they are files in / var / spool / cron / crontabs, it is not intended to edit them directly. Here are some command line options for crontab.

crontab -e edit your crontab file. crontab -l displays your crontab file. crontab -r delete your crontab file.

The traditional cron format contains six fields separated by spaces:

The format description is as follows:

* * * * * * | | | | | | | | | | | + -Year (range: 1900-3000) | | | | + —— Annual month (range: 1-12) | | + ——– Monthly date (range: 1-31) | + ——- — hour (range: 0-23) + ———— minutes (range: 0-59)

16. Do you know any basic Vim commands?

a) save

To save the file, press ESC Button and press :wq! Either :ZZ

b) Exit

To exit from the file without making changes, run the following command :q

c) jump to a specific line in the file

Press ESC then press j Move down one line.

To move up one line, press k On the keyboard

Move the cursor to the beginning of the line ^

Move the cursor to the end of the line $

Move the cursor to the beginning of the file 1G

Move the cursor to the end of the file G

Move the cursor to the beginning of the line number “n” in the file nG

d) Copy text

Move the cursor to the beginning of a string or text. Next, press v on the keyboard and then press the cursor forward to highlight the text. When you reach the end of the text you want to copy, click y yank abbreviation, copy text.

To copy text from the current position to the end of the line- y$

Copy entire line- yy

To copy 4 lines below- 4yy

d) Paste text

To paste text, just press p On the keyboard

d) Delete text

To delete a line, move to the beginning of the line. Press ESC Button and press dd

To delete a single word, place the cursor in front of the word and click dw

Delete text from current word to end of line d$

To delete the following three lines 3dd

17. How can I add the binary to the $ PATH variable?

$ export PATH=$PATH:/path/to/the/binary/file

18. Explain the Grep command and regular expressions?

The Grep command is an expression used to filter results or output. For example, to list directories and search only files with the word “cron”, run the following command:

ls | grep cron

19. What is the difference between umask and ulimit?

Umask stands for “User File Creation Mask”, and it determines the setting of the mask, which controls the file permissions set for files and directories when they are created. Although ulimit is a built-in command of Linux, it can control the resources available to the shell and / or processes started by the shell.

You can restrict users to specific ranges by editing /etc/security/limits.conf, and you can update system-wide settings in /etc/sysctl.conf.

20. Explain the output of the ls command in Linux?

The ls command lists the contents of directories in Linux. It displays files and subdirectories within a directory. When used with other parameters, it can list file permissions and even show hidden files.

21. Explain the output of the top command in Linux?

The top command is a monitoring utility that gives users insight into system metrics such as uptime, average load,% CPU and% memory utilization.

22. What is the process state in Linux?

As its name implies, process state refers to the current state of a Linux process. There are 4 process states, namely “Running”, “Waiting”, “Stopped” and “Zombie”.

23. How to backup or archive files (tar command) in Linux?

To back up the directory, simply run the tar command below

$ tar -cvf tarball_name.tar /path/to/directory

For example, to create an archive in the tar.gz format of the sales.txt file in the / data / reports / path, execute the following command:

$ tar -cvf sales.tar.gz  /data/reports/sales.txt

You can also archive entire directories as follows:

$ tar -cvf repors.tar.gz  /data/reports/

24. How to stop running processes in Linux?

To stop a running process, use the kill command and the PID of the process.

For example, to stop the process using PID 3836, run the following command

kill 3836

25. How to search for files in Linux?

To search for files in Linux, use locate Either find command

26. How to check if a particular service is running?

To check if the service is running, use the following syntax:

systemctl status service_name

For example, to check if Postfix is ​​running, run the following command:

systemctl status postfix

27. How do I start the service on restart?

To start the service on restart, use the following syntax:

systemctl enable service_name

For example, to start the httpd web server after restarting, run

systemctl enable httpd

28. How do you start and stop services?

To start the service on the systemd system, run the following command:

systemctl start service_name

For example, to start the ssh service, run the following command:

systemctl start sshd

To stop the service, run:

systemctl stop service_name

To stop ssh from running:

systemctl stop sshd

29. How to log in to another Linux computer remotely?

You can log in to a remote Linux computer using the SSH protocol or VNC service.

30. How to check disk usage?

Use df Command to check the space used on the hard drive and the remaining / free space. Also, use du Command to check usage of specific files and directories.

31. Why use the export command?

The export command tags and exports environment variables.

32. How to use bash script to get versions from multiple Linux servers?

#we user variable serverlist to keep there path to file with server names
#we write in variable all server list
servers=`cat $serverlist`
#we use variable result to keep there path to file with result

#this print header to file with resilt using tt to add 2 tab symbols
echo -e "Servername tt kernel version"> $result
#this get each line of serverlist one by one and write to server variable
for server in $servers
#this login to server by ssh and get uname -r
kernel=`ssh [email protected]${server} "uname -r"`
#this write server name and kernel version separated by 2 tab to result file
echo -e "$server tt $kernel" >> $result
#end of for loop.

33. What are the minimum requirements for a Linux installation?

As new Linux distributions are released every other week or month, there are no clear minimum requirements. Due to improvements in GUI functionality and architecture, the new version will require higher minimum requirements than the old version. However, any Linux distribution should run on a PC that meets the following minimum requirements:

25 GB of hard disk space
2 Ghz dual core processor
A screen resolution of 1024x768
A CD/DVD ROM or USB port for inserting installation media

34. How to set Linux file / directory permissions?

To set file permissions, use chmod Command, followed by an octal or symbol value, followed by a file or directory name.

For example, to assign a file permission value of 664, run

chmod 664 filename

To assign directory permissions, use -R Option to recursively assign permissions.

chmod -R 664 directory_name

35. How to set file / directory ownership?

To set the file owner, use chown command. E.g chown user:user filename

For directories, use -R Option to recursively assign permissions. E.g

chown -R user:user directory_name

36. How to create users and groups in Linux?

To create a user, run the following command adduser user_nameE.g

adduser john

37. How do I find the kernel / OS version in Linux?

Run command uname -a

38. How to find the IP address of the interface?

You can easily find the IP interface by running the following command ifconfig interface_name Or use the ip command (recommended).


ifconfig eth0

ip addr show

39. What is an initrd picture?

The initial RAM disk (initrd) is the initial root file system mounted before the actual root file system is available. initrd is bound to the kernel and loaded as part of the kernel boot process. The kernel then mounts this initrd as part of a two-phase boot process to load modules to make the actual file system available and obtain the real root file system. Therefore, the initrd image plays a vital role in the Linux boot process.

40. Please explain the terms suid, sgid and sticky bit?

In addition to basic file permissions in Linux, executable files and directories also have some special permissions.

SUID: If the setuid bit is set, when a user executes a file, the process will have the same permissions as the owner of the file being executed.

SGID: Same as above, but inherits the file’s group privileges instead of user privileges at execution time. When creating files in a directory, a similar approach inherits group ownership of the directory.

Sticky bitNote: Sticky bits are used on Linux executables so that they will remain in memory for more time after the first execution, hopefully they will be needed in the near future. But mainly on folders, which means that files or folders created inside stickybit-enabled folders can only be deleted by the owner. A good implementation of sticky bits is / tmp, where each user has write permission, but only the user who owns the file can delete them.

41. What is the run level in Linux? How do I change them?

The run level is an initialization state, which is the state of the entire system. It defines the running system services and identifies them by numbers. In Linux systems, there are 7 different run levels (run levels 0-6) for different purposes. A description is given below.

0: Halt System (To shutdown the system)
1: Single user mode
2: Basic multi user mode without NFS
3: Full multi user mode (text based)
4: unused
5: Multi user mode with Graphical User Interface
6: Reboot System

To change the run level, edit the file “/ etc / inittab” and change the initdefault entry (id: 5: initdefault :). If we want to change the run level on the fly, we can use the “init” command.

For example, when we type “init 3” on the command line, this moves the system from the current run level to run level 3. You can list the current levels by typing the command “who -r”.

42. What is SeLinux?

SELinux is an acronym for Security Enhanced Linux. It is an access control implementation and security function of the Linux kernel. It is designed to protect the server from misconfigurations and / or corrupted daemons. It sets restrictions and instructs server daemons or programs which files they can access and which operations they can perform by defining security policies.

43. Choose 5 Linux commands, what are your options?

1) rsync command

The rsync command can be used to synchronize two directories or directory trees, whether they are on the same computer or on different computers, but it can do much more than that. rsync creates or updates the target directory to make it the same as the source directory.

rsync -aH sourcedir targetdir

The -a option is used for archive mode, which preserves permissions, ownership, and symbolic (soft) links. -H is used to keep hard links. Note that either the source or destination directory can be located on a remote host.

2) sed command

When you need to select a specific line of a file, you will use the sed command. Sed is an abbreviation for Stream Editor and is a way to achieve this. You want to merge multiple files all with titles, or you want to find and replace one file in a batch. Insert a blank line above each line that matches “regex”

$ sed '/regex/{x;p;x;}'

Change “Scarlet” or “Ruby” or “Spike” to “Red”

$ sed 's/scarlet/red/g;s/ruby/red/g;s/puce/red/g'

3) awk command

Awk is a programming language that easily processes structured data and generates formatted reports. It is mainly used for pattern scanning and processing. It searches one or more files to see if they contain lines that match the specified pattern, and then performs the associated operation. Just like the sed command. If you are interested in awk commands, then a liner will make your life easier.

Print specific fields

$ awk -F':' '{ print $1 }' /etc/group
$ date | awk '{print $2 " " $6}'

4) lsof command

lsof is a command line utility that lists information about files opened by various processes. In Unix, everything is a file: pipes, sockets, directories, devices, etc. Therefore, by using lsof, you can get information about any open file.

List processes that open specific files

# lsof /var/log/syslog

List all open files belonging to user-owned processes

# lsof -u username

Kill all processes belonging to a specific user

# kill -9 `lsof -t -u username

List all network connections

# lsof -i

List all network files being used by a specific process

# lsof -i -a -c ssh

List processes that are listening on a specific port

# lsof -i :25

5) grep command

Grep is a command for searching in text or a given file for a line containing a match to a given string or word. By default, grep displays matching lines.

print network connection used by firefox

# netstat -pltnu | grep firefox

Print lines containing “root” in / etc / passwd file

# cat /etc/passwd | grep root

44. What is the difference between a name-based virtual host and an IP-based virtual host?

Virtual hosting is used to host multiple domains on a single apache instance. You can have a virtual host for each IP the server owns, or have the same IP but different ports, or have the same IP, same port, but different host names. The latter is called “name-based virtual hosting”.

On IP-based virtual hosting, we can run multiple websites on the same server, but each website has its own IP address, while in name-based virtual hosting, we host multiple website. But to succeed, you must place DNS records for multiple IP addresses in the IP address database.

45. What are the advantages of network bonding?

Network bonding is a Linux kernel feature that allows multiple network interfaces to be aggregated into a single virtual link. This is a great way to implement redundant links, fault-tolerant or load-balanced networks in a production system. If one of the physical NICs is shut down or unplugged, it will automatically move traffic to the other NIC card. In a similar manner, bonding will increase interface throughput to handle traffic configured in active-active mode.

46. ​​What is the use of / etc / passwd and / etc / shadow files?

The / etc / shadow file stores the actual password in an encrypted format and has some other attributes related to the user password. It mainly saves account aging parameters. All fields are separated by a colon (:). For each user listed in the / etc / passwd file, it contains one entry per line.

47. Why is there no password for ssh login?

To further improve system security, most organizations are turning to key-based authentication instead of password-based authentication. We can enforce key-based authentication by disabling standard password authentication, which includes public key private key pairs. The public key is added to the server configuration file, and the private key is kept secret on the client.

48. What is swappiness in Linux?

The swappiness parameter controls the tendency of the kernel to move processes out of physical memory and into swap disks. Because disks are much slower than RAM, if the process moves out of memory too aggressively, this can result in slower system and application response times.

The value of swappiness can be between 0 and 100

swappiness = 0 tells the kernel to avoid swapping processes out of physical memory as much as possible

swappiness = 100 tells the kernel to actively swap processes out of physical memory and move them to the swap cache

in conclusion

In this tutorial, we explained the most common interview questions in Linux assignments. In addition to these questions, you should also prepare to explain daily Linux tasks, projects, and some key situations encountered. good luck! !!

Also read:

  • Ansible Interview Q & A with Devops
  • 30 Expected DevOps Interview Questions and Answers
  • 70 Shell Script Interview Questions and Answers