Top 100+ Linux Interview Questions and Answers
1. What is Linux?
Linux is an operating system, which is based on Linux Kernel. It is an open-source operating system where it can run on different hardware platforms. It provides a free and low-cost operating system for users. It is a user-friendly environment where they can easily modify and create variations in the source code.
2. Who invented Linux? Explain the history of Linux?
Linus Torvalds created Linux. Linus Torvalds was a student at the University of Helsinki, Finland in 1991. He started writing code on his own to get the academic version of Unix for free. Later on, it became popular as Linux Kernel.
3. What is the difference between Linux and Unix?
Linux vs Unix
And some other differences.
Linux is a Unix clone. But if you consider Portable Operating System Interface (POSIX) standards then Linux can be considered as UNIX.
- Linux Is Just Kernal
All Linux distributions include GUI system, GNU utilities, installation & management tools, GNU c/c++ Compilers, Editors (vi), and various applications like OpenOffice, Firefox.
UNIX operating systems are considered as a complete OS as everything come from a single vendor.
- Security And Firewall
Linux comes with open source Netfilter and IPTables based firewall tool to protect your server and desktop from the crackers and hackers. UNIX operating systems comes with its own firewall products.
- Backup And Recovery
UNIX and Linux come with their own set of tools for backing up data to tape and other backup media. However, both Linux and UNIX share some common tools such as tar, dump/restore, and cpio, etc.
4. What is the core of the Linux operating systems Benefits?
Kernel is the core of the Linux operating system.
5. What is the Linux Kernel?
Kernel is the heart of the operating system. It acts as a bridge between software and hardware. If Software requests the hardware, then kernel delivers the data between software and hardware. For example, if you want to play a song you should launch your default player, it requests the kernel to play a song, now kernel will contact the hardware to seek the permissions or to seek the hardware components like if you plugged in any headset to the device. Most of the Android phones use Linux kernels.
Yes, the kernel can edit, because it is released under General Public License.
For more detailed information about Kernel: Read more at Linux Kernel Tutorial
6. What is BASH?
Bash is a Unix shell and command processor written by Brian Fox for the GNU project. It is free software and acts as a replacement for Bourne Shell. It is an interpreted and not compiled process which can also be run in the terminal window. This allows users to write commands and cause actions. Bash is capable of reading commands from shell scripts.
7. 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.
8. What is CLI?
CLI means Command language Interpreter. It interacts with the computer program, where the user issues command in the form of text lines. It Interacts with the computer terminals also, the interface accepts the text lines and converts them as a command to the operating system.
9. What is the advantage of Open Source?
Linux was one of the first open-source technologies, many programmers added software that completely open to the users, which means you can download the file and change the code as you like. It has a wide range of options for users and increased security.
10. What is the disadvantage of Open Source?
Disadvantages of Open Source Operating System mentioned below
- Difficulty of use
- Compatibility Issues
- Liabilities and warranties
- Hidden costs
11. What is Shell?
Shell is a computer program which acts as an interface between the user and the kernel. Users can communicate with the kernel by writing programs, commands and scripts on the shell. It accepts human-readable commands and converts them into the kernel understandable language.
12. How many types of Shells are there in Linux?
They are five Shells in Linux:
- C Shell (csh): It is like C syntax and provides spelling checking and job control.
- Korn Shell (ksh): Is a high-level programming language shell.
- Z Shell (Zsh): It provides some unique nature like it observes login/logout watching, file name generating, startup files, closing comments.
- Bourne Again Shell (bash): It is the default to Linux distributions.
- Friendly Interactive Shell (Fish): It provides web-based configuration, auto-suggestions, etc.
13. What are the basic components of Linux?
Basic components of Linux
- Kernel: It is the core component of the Linux, it acts as an interface between software and hardware.
- Shell: It acts as an interface between the user and the Kernel.
- GUI: It stands for Graphic User Interface, which is another way for the user to interact with the system. But it is unlike images, buttons, text boxes for interaction.
- System Utilities: These are the software functions that allow users to manage the computer.
- Application Programs: Set of functions designed to perform a set of tasks.
14. How do you open a command prompt when issuing a command?
Launch your terminal by pressing CTRL+ALT+T or by giving terminal in the menu search bar.
15. What is a swap space?
Swap Space is used when then physical Ram memory is running out. It will move the Ram inactive pages to the swap space. It can consider in the form of a dedicated swap partition or a swap files.
16. What is the GUI?
GUI means Graphical User Interface. It is a human-computer interface that uses windows, images, icons and menus which can be manipulated by using a mouse. Most of the modern applications in electronic gadgets communicate with the user through GUI. GUI is a combination of graphical and textual interaction that uses buttons, menus, message boxes, etc.
17. Explain File Permissions types in Linux?
Each file or directory has 3 permissions
- Read– It refers that only they can read the file.
- Write– It refers that they can write the file or modify the file of a directory.
- Execute– It affects the user’s capability to execute the file or to view the file of a directory.
18. What are the environmental variables?
They are dynamic values that affect the process of programs on a computer. They exist in every operating system and their types may vary. They can be created, edited, saved and deleted and they also give the information about the system behaviour.
19. What are the symbolic links?
It will be redirected to another file using its path. Target files do not contain any data. Symbolic links redirect to another entry somewhere in the file system. If the target file is deleted, the link to that file is removed, but not the file.
20. What are the basic components of Linux?
The basic components of Linux are given below:
21. What are the hard links?
A hard link is another name for an existing file on Linux. We can create so many numbers of hard links, for any file. They can create links for other hard links.
22. What is redirection?
Redirection can be defined as changing the standard input and output devices. To redirect metacharacters are used, you can redirect the file or program.
23. What are Daemons?
A Daemons is a background process which accepts the requests for service from other computers, most of the operating systems use daemons in other forms.
24. Describe the root account?
Root is the user name, that default have access to all files and commands. The root user can do many things, but an ordinary user cannot do like installing software, change file permissions, etc
25. Explain virtual desktop?
Virtual Desktop is a user interface when you are facing the problem of how to manage multiple windows on your desktop, virtual desktop serves as an alternative. Virtual desktop stores remote server and allow you to use one or more programs on a clean slate.
26. What are the different modes when using the v editor?
There are three kinds of modes in vi editors. They are
- Command Mode/ Regular Mode
- Insertion Mode/Edit Mode.
- Ex Mode/ Replacement Mode.
27. What are inode and process id?
inode is a unique name given to each file and process id is a unique name given to each process.
28.What are the Process states in Linux?
Five process states in Linux. They are
- New/ Ready: A new process is created and ready to run.
- Running: The process is being executed.
- Blocked/ Wait: The process is waiting for input from the user.
- Terminated/ Completed: The process completed the execution or terminated by the operating system.
- Zombie: The process is deleted, but still the information regarding the process exists in the process table.
29. Explain Process Management System Calls in Linux?
The process management system calls in Linux:
- fork(): Used to create a new process.
- exec(): Execute new process.
- wait(): wait until process execution.
- exit(): exit from the process.
System calls to get the Process id :
- getpid(): to find the unique process id.
- getppid(): to find the unique parent process id.
30. Explain File Permission groups in Linux?
There are three user based permission groups for each file and directory.
- Owner: Owners only will have to access the file or directory, they will not impact the actions of other users.
- Group: These permissions apply only to the group, that has been assigned to the file or directory. They will not impact the actions of other users.
- All Users: These permissions are applied to all users on the system.
31. What Is a File system in Linux?
Linux file system stores and handles the data. Without a file system, it cannot know where the file starts from and where the file ends.
32. Explain different file system types in Linux?
In Linux, there are many file systems:
Ext, Ext2, Ext3, Ext4, JFS, XFS, btrfs, ufs, autofs, devpts, ntfs and swap.
Linux Admin Interview Questions
33. What is umask?
unmask stands for user file creation mode. When the user creates any file, it has default file permissions. So unmask will specify few restrictions to the newly created file (it controls the file permissions).
umask [-S] [mask]
34. How to set the mask permanently for a user?
If the unmask command invoked without any arguments, it means it will display the current mask.
To set the unmask permanently, we have two types.
- Ocotal representation.
- Symbolic representation.
35. What is network bonding in Linux?
Network Bonding is a process of combining more than two network interfaces to form a single network interface. It offers performance improvement and redundancy by increasing network throughput and bandwidth. No need to worry if one interface is down or unplugged because the other will work. The behaviour of the bonded interface depends on the bonding method.
36. What are the different modes of Network bonding in Linux?
- Mode-0(balance-rr): It is a default mode and based on Round-Robin policy. It offers fault tolerance and load balancing features. It used round-robin fashion to transmit the packets.
- Mode-1(active-backup): It is based on Active Backup policy and only one slave will act in the band and another one will act when the others fail in the band. It also provides fault tolerance.
- Mode-2(balance-xor): It sets a xor mode between the source Mac address and destination Mac address to provide fault tolerance.
- Mode-3(broadcast): It is based on broadcast policy and transmitted everything in the slave interface. It also provides fault tolerance and it can be used only for a particular purpose.
- Mode-4(802.3ad): It is a dynamic aggregation mode, it created aggregation groups which is having the same speed. It uses transmit hashing method to select the slaves for outgoing traffic.
- Mode-5(balance-tlb): The outgoing traffic is according to the current load on the slave, and the incoming traffic is received by the slave. It is called an adaptive transmit load balancing mode.
- Mode-6(balance-alb): It is an adaptive load balancing mode. It does not require any switch support.
37. How to check the default route and routing table?
To display the default route and routing table, we use the following commands.
- $ nestat-rn
38. How to check which ports are listening in my Linux Server?
We have two commands to check which ports are in listening in Linux Server. Following are the two commands
1 # netstat –listen
2 # netstat -l
39. Where the kernel modules are located?
lib/modules/kernel-version/, this directory stores all the information about the compiled drives under the Linux system. Using lsmod command also we can see the installed kernel modules.
40. How to change the default run level in Linux?
To change the default run level in Linux use init command.
41. How to share a directory using nfs?
To share a directory using NFS, first edit the configuration file and ‘/etc/exports’ and add an entry like directory name ‘/’. Now restart the NFS service.
42. What are the default ports used for SMTP, DNS, FTP, DHCP, SSH, and squid?
Details mentioned below
43. How to lock user account in Linux?
Locking user account is done for the security purpose so that unauthorized users cannot login. So, we have a few ways to lock the user account. Some of them are below.
Lock or disable the password using passwd command.
Expire the user account using usermod command or chage command.
Changing the shell using nologin command ( /sbin/nologin ).
Linux Commands Interview Questions
44. What is ls command and what it does?
It is one of the basic commands in Linux. It is used to list all the files and directories in the file system.zom
<span style=”color: #ecf0f1; background-color: #000000;”>ls [OPTIONS] [FILES]</span>
We can use it without passing the arguments, then it will list all the files in the current working directory. Files will be displayed in alphabetical order.
<span style=”background-color: #000000; color: #ecf0f1;”>Is</span>
To list the specific directory files use directory name in the syntax, follow as shown in the below syntax.
We can also pass multiple directories names in the syntax, but separated by space.
ls /etc /var /etc/passwd
45. What is tail command in Linux?
The Tail command print last N number of lines of the given data, it prints 10 lines by default.
tail [OPTION]… [FILE]
$ cat names.txt
Now, check the syntax without giving any option or input.
$ tail state.txt
46. What is grep command in Linux?
grep command is a filter which is used to the global search for regular expressions.
grep [options] pattern [files]
47. What is ps command in Linux?
ps command display the current process status of the system. And it displays the process id’s with some other related data also.
PID TTY TIME CMD
12330 pts/0 00:00:00 bash
21621 pts/0 00:00:00 ps
48. What is env command in Linux?
env is a shell command is used to print a list of current environmental variables and it can run another process in another environment without any modification of the current environment.
env [OPTION]… [-] [NAME=VALUE]… [COMMAND [ARG]…]
49. What is top Command in Linux?
Top command used to show the system process and it displays and update the sorted process information.
50. What is netstat command in Linux?
Netstat command gives various information about the network and routing tables, interface statics and more about the system.
51. What is lsof command in Linux?
lsof means List of file, we can know which file is opened by which process.
52. Explain about chmod command?
This command is used to change the permission of files and directories. It’s an important command so, I’ll explain it briefly. Therefore, on the whole, there are three ty0pe of permission, read, write and execute and are represented by numbers as shown below.
- 4 – read permission
- 2 – write permission
- 1- execute permission
$ chmod options permissions file name
$ chmod [OPTION]… MODE[,MODE]… FILE…
$ chmod [OPTION]… OCTAL-MODE FILE…
$ chmod [OPTION]… –reference=RFILE FILE…
53. Explain about chown command?
Chown command: The command “chown” stands for change file owner and Group. This command is used to change the ownership of one or more files or folders for a specified user or group.
$ chown [OPTION]… [OWNER][:[GROUP]] FILE…
$ chown [OPTION]… –reference=RFILE FILE…
54. What is cp command in Linux?
cp command: cp command is used to copy files and directories. It is also used to backup files or directories.
$ cp file name
55. How to remove file or directory from the system in Linux?
rm command: The rm command is used to remove directory or file specified on the command line. You need to be careful while removing any file or directory.
56. What is mkdir in Linux?
mkdir, command allow users to create directories in the Linux. User can create multiple directories at once and can set the permissions to the directories.
mkdir [options…] [directories …]
57. Explain rmdir command in Linux?
The rmdir is used to remove each directory specified on the command line.
rmdir [-p] [-v | –verbose] [–ignore-fail-on-non-empty] directories
58. How to exit from vi editors?
We can use two commands to exit from the vi editor. They are
- Wq: wq command saves the current work and exits from the vi editor.
- q!: q! Command does not save the current work, but it exits from the vi editor.
59. How to delete information from a file in vi?
Following commands are used to delete information from a file in vi editors.
- Command x deletes the current character.
- Command dd deletes the current line.
60. Enlist some Linux file content commands?
File content commands
head: Display top lines of the file.
tail: Display last lines of the file.
cat: Concatenate more than 2 files.
more: Displays the content in pager form to view in the terminal.
Linux Technical Interview Questions and Answers for Experienced
61. Enlist some Linux distributors (Distros) along with its usage?
We have so many Linux Distributors, among them, we discuss a few important ones.
Linux Mint: It is stable and robust. Linux Mint uses mate desktop and cinnamon.
Debian: It stands for robustness, stability, and well-oiled release cycle. It is user-friendly. Debian version 8 will be replaced by version 9.
Ubuntu: It is available for both desktop and server editions and is based on Debian.
openSUSE: It is a good choice for new users and existing users.
Manjaro: It gives a pleasant experience for new and experienced users.
62. Why we use LINUX?
We are some many reasons, in that few important reasons are listed out. Following are
High Stability: It is very stable and does not lead to crashes, it runs fastly as it is when it installed first.
Security: It is a dependable server, that offers high security to the user. Using Linux on your system it is easy to avoid virus and malware. The attacker cannot change any changes in the system until the user logged in at as root user.
Easy to Operate: Linux is easy to operate and we can install easily on to the system because all the variants of the Linux have there owned software repositories. You can update the system periodically with just a few clicks or you can set automatic updation.
Hardware Compatibility: Linux can use on any hardware, it doesn’t have any hardware restrictions. It uses efficiently all system resources.
Open Source: The source code is available as it is under Free and Open Source Software(FOSS).
63. What are the features of the Linux operating system?
Following are the features of the Linux Operating System
Portable: Software can work on different types of hardware in the same way. It can carry easily in pen drives and memory cards.
Open Source: Source code available for free, and its community-based development project.
Multi-User: Multiple users can use ram, applications and run programs at the same time.
Multiprogramming: Multiple program or applications can run at the same time.
Shell: It has a special interpreter program where you can execute programs and commands of the system.
Security: It provides authentication, authorization, and encryption to provide security to the data.
64. Differentiate between BASH and DOS?
65. What is meant by internal commands and external commands?
- Internal Commands: Commands directly run by the shell is known as internal commands and there is no separate process to run the commands.
- External Commands: Commands which are run by the kernel is known as external commands and for every single command has its own unique process id.
Linux Networking Interview Questions
66. What is meant by PIPE in Linux?
It is a form of redirection that is used in Linux, it is used to combine more than two commands and the output of one command can take as input to the next command.
command_1 | command_2 | command_3 | …. | command_N
67. Describe how a parent and child process communicates each other?
Parent process communicates with the child process by using pipes, sockets, messages queues and more.
68. 68. What is Stateless Linux Server?
It is a centralized server which does not have any exists states on the working station. It may have scenarios when a state of a particular system takes snapshot then, the user wants all other machines to be in that particular state.
69. Explain features of Stateless Linux Server?
Stores the prototype of every system.
Stores the snapshot was taken.
Stores the home directories.
Uses LDAP, which contains the information about which snapshot should run on which system.
It is a process whose execution is completed but even the information exists in the process table. It occurs for the child process because the parent process needs to read the child process status. Once it is completed using the wait system call, then the zombie process is removed from the process table. This is known as Zombie Process.
71. Explain the work of Ctrl+Alt+Del key combination on the Linux operating system?
In Linux, Ctrl+Alt+Del key is used to restart the computer, and it does not display any confirmation message before rebooting the system.
72. Why is Linux considered more secure than other operating systems?
Linux is an open-source operating system, nowadays it is rapidly growing in the technology market. We have a few reasons why Linux is more secure than other OS.
The perk of accounts: Linux allows only a few users to access the system. Thus, the virus cannot attack the whole system, it may cause only a few files in the system.
Strong Community: Linux users first accomplished the files before they open. So they can save their systems from vulnerabilities.
Iptables: Iptables used by the Linux because it checks the security circle of the system.
Different Working Environment: Linux system has different working environments like Linux Mint, Debian, Arch and many more, these working environments protect from the virus.
Recording in Linux: It maintains log history because later it can view the details of the system files easily.
Few User: Linux users are less compared to others, due to this security will be more.
73. What is tail command in Linux?
The tail command displays the last part of a file. Generally, users don’t need every logline to troubleshoot. Instead, you want to check what your logs say about the most recent request to your application.
$ tail -n 100 /var/log/httpd/access_log
74. What is cat command in Linux?
In Linux cat command concatenates and prints files. Users might issue cat to check the contents of your dependencies file or to confirm the version of the application that you have already built locally.
$ cat requirements.txt
75. What is grep command in Linux?
grep searches file patterns. If you are looking for a specific pattern in the output of another command, grep highlights the relevant lines. Use this grep command for searching log files, specific processes, and more.
$ cat tomcat.log | grep org.apache.catalina.startup.Catalina.start
12-Jan-2018 17:08:35.542 INFO [main] org.apache.catalina.startup.Catalina.start Server startup
76. What is ps command in Linux?
ps command displays process status. Use this ps command to determine a running application or confirm an expected process.
ps Command Example:
$ ps -ef
$ ps -ef | grep tomcat
77. What is env command in Linux?
env command allows users to set or print the environment variables. During troubleshooting, users can find it useful for checking if the wrong environment variable prevents your application from starting.
env Command Example:
78. What is top Command in Linux?
Top command displays and updates sorted process information. Use this top command to determine which processes are running and how much memory and CPU they are consuming.
79. What is netstat command in Linux?
Netstat command in Linux shows the network status. This netstat command shows network ports in use and their incoming connections.
80. What is lsof command in Linux?
ls of command lists the open files associated with your application.
81. What is df command in Linux?
Users can use df command to troubleshoot disk space issues. Here df stands for display free disk space.
df Command Example:
82. What is du command in Linux?
du command in Linux is used to retrieve more detailed information about which files use the disk space in a directory.
du Command Example:
$ du -sh /var/log/*
83. What is iptables command in Linux?
Iptables command blocks or allows traffic on a Linux host, similar to a network firewall. This iptables command may prevent certain applications from receiving or transmitting requests.
Linux Vs Windows
84. What does cd - command do?
cd- command go to the previous directory.
85. What does cd command do?
Go to $HOME directory
86. What does (cd dir && command) do?
cd dir && command goes to the dir, execute the command and return to the current directory.
87. How do you combine two lines from two sorted files in Linux?
Use this command: comm file1 file2.
88. What does pushd command do?
pushd command put current dir on the stack so you can pop back to it.
89. What is ls -lSr command?
ls – ISr command shows files by size, biggest file will be displayed last
90. What is du -s * | sort -k1,1rn | head command used for?
This command shows top disk users in current dir.
91. What does this du -hs /home/* | sort -k1,1h command do?
This command sort path by easy to interpret disk usage.
92. What is df -h command?
This command show free space on mounted file systems
93. What is df -i command?
df -I command shows free inodes on mounted filesystems.
94. What is fdisk -l command used for?
fdisk -I command show disks partitions sizes and types (run as root).
95. How do you kill the program using one port in Linux?
Use this command to kills the program using one port: sudo fuser -k 8000/tcp
96. How do you limit memory usage for commands?
ulimit -Sv 1000 # 1000 KBs = 1 MB
ulimit -Sv unlimited # Remove limit
97. How do you get full path of a file in Linux?
<strong style=”font-family: -apple-system, BlinkMacSystemFont, ‘Segoe UI’, Roboto, Oxygen, Ubuntu, Cantarell, ‘Open Sans’, ‘Helvetica Neue’, sans-serif; color: #e74c3c;”>Ans:</strong> Use this command: readlink -f file.txt
98. How do you list contents of tar.gz and extract only one file?
Use these commands:
tar tf file.tgz
tar xf file.tgz filename
99. How do you find who is logged in?
Use this command to find who logged in: w
100. How do you check permissions of each directory to a file?
It is useful to detect permissions errors, for example when configuring a web server.
namei -l /path/to/file.txt
101. How do you run the command every time a file is modified?
Use this command to do:
while inotifywait -e close_write document.tex
102. How to copy text to the clipboard?
Use this command: cat file.txt | xclip -selection clipboard
103. How do you check resources usage?
Use this command to check resource usage: /usr/bin/time -v ls
104. How do you run a command for a limited time?
Use this command: timeout 10s ./script.sh
# Restart every 30 minutes
while true; do timeout 30m ./script.sh; done