Linux Interview Questions
Linux Interview Questions
1. What is Linux?
Linux is an Open-Source Operating System based on Unix. Linux was first introduced by Linus Torvalds. The
main purpose of Linux was to provide free and low-cost Operating System for users who could not afford
Operating Systems like Windows or iOS or Unix.
Both free distributions and paid distributions are Different levels of UNIX have a
Price
available. different cost structure
Portability Yes No
Linux kernel refers to the low-level system software. It is used to manage resources and provide an interface
for user interaction.
Yes, it is legal to edit Linux Kernel. Linux is released under the General Public License (General Public
License). Any project released under GPL can be modified and edited by the end users.
4. What is LILO?
LILO stands for LInux LOader. LILO is a Linux Boot Loader that loads Linux Operating System into the main
memory to begin execution. Most of the computers come with boot loaders for certain versions of Windows or
Mac OS. So, when you want to use Linux OS, you need to install a special boot loader for it. LILO is one such
boot loader.
When the computer is started, BIOS conducts some initial tests and transfers control to the Master Boot
Record. From here, LILO loads the Linux OS and starts it.
The advantage of using LILO is that it allows fast boot of Linux OS.
Kernel: It is the core component of the Operating System that manages operations and hardware.
Shell: Shell is a Linux interpreter which is used to execute commands.
GUI: GUI stands for Graphical User Interface which is another way for a user to interact with the
system. But unlike CLI, GUI consists of Images, Buttons, TextBoxes for interaction.
System Utilities: These are the software functions that allows the user to manage the computer.
Application Programs: Software programs or set of functions designed to accomplish a specific task.
bash: Bourne Again Shell is the default for most of the Linux distributions
ksh: Korn Shell is a high-level programming language shell
csh: C Shell follows C like syntax and provides spelling correction and Job Control
zsh: Z Shell provides some unique features such as filename generation, startup files, login/logout
watching, closing comments etc.
fish: Friendly Interactive Shell provides some special features like web-based configuration, auto-
suggestions, fully scriptable with clean scripts
Swap Space is the additional spaced used by Linux that temporarily holds concurrently running programs
when the RAM does not have enough space to hold the programs. When you run a program, it resides on the
RAM so that the processor can fetch data quickly. Suppose you are running more programs than the RAM can
hold, then these running programs are stored in the Swap Space. The processor will now look for data in the
RAM and the Swap Space.
8. What command would you use to check how much memory is being used
by Linux?
free -m
vmstat
top
htop
You can change the permission of a file or a directory using the chmodcommand. There are two modes of using
the chmod command:
1. Symbolic mode
2. Absolute mode
Symbolic mode
For example, if you want to set the permission such that the user can read, write, and execute it and
members of your group can read and execute it, and others may only read it.
Absolute mode
The Absolute mode follows octal representation. The leftmost digit is for the user, the middle digit is for the
user group and the rightmost digit is for all.
Below is the table that explains the meaning of the digits that can be used and their effect.
0 No permission –––
1 Execute permission ––x
2 Write permission –w–
3 Execute and write permission: 1 (execute) + 2 (write) = 3 – wx
4 Read permission r––
5 Read and execute permission: 4 (read) + 1 (execute) = 5 r–x
6 Read and write permission: 4 (read) + 2 (write) = 6 rw –
7 All permissions: 4 (read) + 2 (write) + 1 (execute) = 7 rwx
For example, if you want to set the permission such that the user can read, write, and execute it and
members of your group can read and execute it, and others may only read it.
inode is the unique name given by the operating system to each file. Similarly, process id is the unique id
given to each process.
Syntax: $ pwd
ls: Lists all the files and directories in the present working directory.
Syntax: $ ls
Virtual Desktop is a feature that allows users to use the desktop beyond the physical limits of the screen.
Basically, Virtual Desktop creates a virtual screen to expand the limitation of the normal screen.
1. Switching Desktops
2. Oversized Desktops
Switching Desktops
In the case of Switching Desktops, you can create discrete virtual desktops to run programs. Here, each
virtual desktop will behave as an individual desktop and the programs running on each of these desktops is
accessible only to the users who are using that particular desktop.
Oversized Desktops
Oversized Desktops do not offer a discrete virtual desktop but it allows the user to pan and scroll around the
desktop that is larger in size than the physical screen.
Grep stands for Global Regular Expression Print. The grep command is used to search for a text in a file
by pattern matching based on regular expression.
Example:
This command will print the count of the word “linux” in the “interview.txt” file.
The ls command is used to list the files in a specified directory. The general syntax is:
$ ls <options> <directory>
For example, if you want to list all the files in the Example directory, then the command will be as follows:
$ ls Example/
There are different options that can be used with the ls command. These options give additional information
about the file/ folder. For example:
The redirection operator is used to redirect the output of a particular command as an input to another
command or file.
‘>’ overwrites the existing content of the file or creates a new file.
‘>>’ appends the new content to the end of the file or creates a new file.
Now when you use the ‘>’ redirection operator, the contents of the file are overwritten.
Suppose you want to extract all the files from the archive named sample.tar.gz, then the command will be:
Suppose you want to create an archive of all the files stored in the path /home/linux/, then the command will
be:
18. What is the minimum number of disk partitions required to install Linux?
You can use the cp command to copy a file in Linux. The general syntax is:
$ cp <source> <destination>
Every process has a unique process id. To terminate the process, we first need to find the process id.
The ps command will list all the running processes along with the process id. And then we
use the kill command to terminate the process.
$ ps
Suppose the process id of the process you want to terminate is 3849, then you will have to terminate it like
this:
$ kill 3849
There is no specific command to rename a file in Linux. But you use the copy or move command to rename
the file.
$ mv <oldname> <newname>
$ cp <oldname> <newname>
$ rm <oldname>
$ mount -l
You can use the locate command to find the path to the file.
Suppose you want to find the locations of a file name sample.txt, then your command would be:
$ locate sample.txt
26. How would you create a text file without opening it?
The touch command can be used to create a text file without opening it. The touch command will create an
empty file. The syntax is as follows:
$ touch <filename>
Suppose you want to create a file named sample.txt, then the command would be:
$ touch sample.txt
There are two commands that can be used to delete a directory in Linux.
rmdir
rm -rf
Note: The command rm -rf should be used carefully because it will delete all the data without any warnings.
There are two commands to schedule tasks in Linux: cron and at.
The cron command is used to repeatedly schedule a task at a specific time. The tasks are stored in acron file
and then executed using the cron command. The cron command reads the string from this file and
schedules the task. The syntax for the string to enter in the cron file is as follows:
0 16 * * 0 <command>
The at command is used to schedule a task only once at the specified time.
Suppose you want to shut down the system at 6 pm today, then the command for this would be:
29. Suppose you try to delete a file using the rm command and the deletion fails.
What could be the possible reason?
The path specified to the file or the file name mentioned might be wrong
The user trying to delete the file might not have permissions to delete the file.
$ service --status-all
To start:
To stop:
This command is used to display the free, used, swap memory available in the system.
$ free
The root account is like a systems administrator account and allows you full control of the system.
Here you can create and maintain user accounts, assigning different permissions for each
account. It is the default account every time you install Linux.
35. What is CLI?
CLI is short for Command Line Interface. This interface allows the user to type declarative
commands to instruct the computer to perform operations. CLI offers greater flexibility. However,
other users who are already accustomed to using GUI find it difficult to remember commands
including attributes that come with it.
GUI, or Graphical User Interface, make use of images and icons that users click and manipulate
as a way of communicating with the computer. Instead of having to remember and type
commands, the use of graphical elements makes it easier to interact with the system, as well as
adding more attraction through images, icons, and colors.
It contains locally installed files. This directory matters in environments where files are stored on
the network. Specifically, locally-installed files go to /usr/local/bin, /usr/local/lib, etc.). Another
application of this directory is that it is used for software packages installed from source, or
software not officially shipped with the distribution.
44. State the difference between swap partition and a swap file?
The Linux Operating System uses reserved disk block in the hard drive to swap. This is known as Swap Partition as no
other files can be traced in the swap partition. In case of Windows OS, the swap space or partition is called swap file or
page file.
45. What is a zombie process?
A zombie process is also known as a defunct process. It is a process in the terminated state and has completed execution
via the exit system call but still has an entry in the table of processes.