Top 48 Linux Interview Questions & Answers (Updated 2020) PDF
Top 48 Linux Interview Questions & Answers (Updated 2020) PDF
If you are a beginner (with some knowledge of Linux or having certi cation) or with
professional Linux administration experience, then following Q & A help for your interview
preparation.
Kernel: This is the core of the Linux system. It's responsible for interacting with the
hardware components and ensuring the operating system communicates with hardware
devices.
Shell: A shell is an interface between the Linux user and the kernel. It's in the shell that
commands are issued by the user and are thereafter executed by the operating system.
System libraries: These are special programs or functions which are responsible for
implementing a majority of the functionalities of the operating system without relying on
the kernel modules' code access rights.
System Utilities: These are speci c programs that executed certain tasks. e.g LibreO ce,
Brasero, Gparted.
Linux is a clone of the UNIX system from which Linux is derived from. While Linux is
opensource and free to use, UNIX is a proprietary operating system.
Explanation
File systems, in general, have two parts: the metadata or the “data” about the data and the
data itself. Metadata consist of information about the data. More precisely it includes
information such as the Access Control List (ACL), the date the le was modi ed, le owner,
le permissions, size of le, device ID, uid of the le, etc. This type of information is key to a
le system otherwise we just have a bunch of bits on the storage media that don’t mean
much. Inodes store this metadata information and typically they also store information
about where the data is located on the storage media.
In a le system, inodes consist roughly of 1% of the total disk space, whether it is a whole
storage unit (hard disk, thumb drive, etc.) or a partition on a storage unit. The inode space is
used to track the les stored on the hard disk. The inode entries only points to these
structures rather than storing the data. Each entry is 128 bytes in size.Space for Inodes is
allocated when the operating system or a new le system is installed and when it does its
initial structuring. So this way we can see that in a le system, the maximum number of
Inodes and hence maximum number of les are set. Now, the above concept brings up
another interesting fact. A le system can run out of space in two ways:
https://linoxide.com/linux-how-to/linux-interview-questions-answers/ 2/20
1/25/2020 Top 48 Linux Interview Questions & Answers (Updated 2020)
ls -li
total 3336
57741 -rw-r--r-- 1 root root 3412144 Nov 20 17:26 coreutils-8.22-18.el7.x8
6_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
c) Removing the original le that your hard link points to does not remove the hardlink itself;
the hardlink still provides the content of the underlying le.
d) If you remove the hard link or the symlink itself, the original le will stay intact.
e) Removing the original le does not remove the attached symbolic link or symlink, but
without the original le, the symlink is useless
In Linux, there are 3 main types of le permissions: read, write and execute. These
permissions can be assigned to either a le or a directory recursively. Being a multi-user
system, you can assign these permissions to the root user, groups or even to other users
using the system.
Read: The read permission grants uses the ability to open and read a le.
Write: Write permission allows a user to open and modify or edit the le's contents and
save the changes.
Execute: This allows a user to execute or run the le or a program or shell script which
is executable.
mkdir directory_name
mkdir data
The rm command is mostly used with the -R ag for recursively removing directories.
https://linoxide.com/linux-how-to/linux-interview-questions-answers/ 4/20
1/25/2020 Top 48 Linux Interview Questions & Answers (Updated 2020)
You can also use cat command followed by the redirection operator or greater than sign
>
followed by the name of the le. Next, type the content of the le and lastly press CTRL +
D to exit the le.
mv /data/files/file1.doc /data/files/file2.doc
cp /source/of/the/file /destination/of/the/file
df -aTh
To nd more information about the mount points on your system, execute the command:
findmnt
cat /proc/self/mounts
Also, you can use the mount command as shown
mount -l
https://linoxide.com/linux-how-to/linux-interview-questions-answers/ 5/20
1/25/2020 Top 48 Linux Interview Questions & Answers (Updated 2020)
touch new_file
* * * * * *
| | | | | |
| | | | | +-- Year (range: 1900-3000)
| | | | +---- Day of the Week (range: 1-7, 1 standing for Monday)
| | | +------ Month of the Year (range: 1-12)
| | +-------- Day of the Month (range: 1-31)
| +---------- Hour (range: 0-23)
+------------ Minute (range: 0-59)
https://linoxide.com/linux-how-to/linux-interview-questions-answers/ 6/20
1/25/2020 Top 48 Linux Interview Questions & Answers (Updated 2020)
To save a le, press ESC button and press :wq! OR :ZZ
b) Exit
d) Copy text
Move the cursor to the beginning of the string or text. Next hit v on your keyboard and press
cursor forward to highlight text. Once you get to the end of text that you wish to copy, hit y
short for yank, to copy the text.
d) Paste text
d) Delete text
To delete a line, move to the beginning of a line. Press the ESC button and press dd
To delete a single word, place the cursor in front of the word and hit dw
To delete text from the current word to the end of the line hit d$
$ export PATH=$PATH:/path/to/the/binary/file
ls | grep cron
You can limit user to speci c range by editing /etc/security/limits.conf at the same time
system wide settings can be updated in /etc/sysctl.conf
https://linoxide.com/linux-how-to/linux-interview-questions-answers/ 8/20
1/25/2020 Top 48 Linux Interview Questions & Answers (Updated 2020)
For example, to stop a process with PID 3836, run the command
kill 3836
https://linoxide.com/linux-how-to/linux-interview-questions-answers/ 9/20
1/25/2020 Top 48 Linux Interview Questions & Answers (Updated 2020)
https://linoxide.com/linux-how-to/linux-interview-questions-answers/ 10/20
1/25/2020 Top 48 Linux Interview Questions & Answers (Updated 2020)
Use the df command to check the space used on your hard drive and the space
remaining / free space.
Additionally, use the du command to check usage by speci c les and directories.
32. How to get version from multiple Linux servers using bash
script?
#!/bin/bash
#we user variable serverlist to keep there path to file with server names
serverlist='server_list.txt'
#we write in variable all server list
servers=`cat $serverlist`
#we use variable result to keep there path to file with result
result='result.txt'
#this print header to file with resilt using \t\t to add 2 tab symbols
echo -e "Servername \t\t kernel version"> $result
#this get each line of serverlist one by one and write to server variable
for server in $servers
do
#this login to server by ssh and get uname -r
kernel=`ssh root@${server} "uname -r"`
#this write server name and kernel version separated by 2 tab to result fi
le
echo -e "$server \t\t $kernel" >> $result
#end of for loop.
done
https://linoxide.com/linux-how-to/linux-interview-questions-answers/ 11/20
1/25/2020 Top 48 Linux Interview Questions & Answers (Updated 2020)
For a directory use the -R option to assign permissions recursively. For example
adduser john
37. How to nd the kernel/OS version in Linux?
Run the command uname -a
https://linoxide.com/linux-how-to/linux-interview-questions-answers/ 12/20
1/25/2020 Top 48 Linux Interview Questions & Answers (Updated 2020)
For example
ifconfig eth0
ip addr show
SUID: If setuid bit is set, when the le is executed by a user, the process will have the same
rights as the owner of the le being executed.
SGID: Same as above, but inherits group privileges of the le on execution, not user
privileges. Similar way when you create a le within the directory, it will inherit the group
ownership of the directories.
https://linoxide.com/linux-how-to/linux-interview-questions-answers/ 13/20
1/25/2020 Top 48 Linux Interview Questions & Answers (Updated 2020)
imply that a le or folder created inside a stickybit enabled folder could only be deleted by
the owner. A very good implementation of sticky bit is /tmp , where every user has write
permission but only users who own a le can delete them.
41. What are the run levels in linux and how to change them?
A run level is a state of init and the whole system that de nes what system services are
operating and they are identi ed by numbers. There are 7 different run levels
(https://linoxide.com/linux-command/how-do-you-change-runlevels-in-linux/) present (run
level 0-6) in a Linux system for the different purpose. The descriptions are given below.
To change the run level, edit the le “/etc/inittab” and change initdefault entry (
id:5:initdefault:). If we want to change the run level on the y, it can be done using ‘init’
command.
For example, when we type ‘init 3' in the command line, this will move the system from
current runlevel to runlevl 3. Current level can be listed by typing the command 'who -r'
https://linoxide.com/linux-how-to/linux-interview-questions-answers/ 14/20
1/25/2020 Top 48 Linux Interview Questions & Answers (Updated 2020)
The -a option is for archive mode which preserves permissions, ownerships and symbolic
(soft) links. The -H is used to preserve hard links. Note that either the source or target
directories can be on a remote host.
2) sed command
$ sed '/regex/{x;p;x;}'
$ sed 's/scarlet/red/g;s/ruby/red/g;s/puce/red/g'
3) awk command
Awk is a programming language that allows easy manipulation of structured data and the
generation of formatted reports. It is mostly used for pattern scanning and processing. It
searches one or more les to see if they contain lines that match with the speci ed
patterns and then perform associated actions. It is like sed command. If you are interested
with awk command one liner (https://linoxide.com/linux-command/awk-linux-famous-
oneliners/) makes your life easy.
https://linoxide.com/linux-how-to/linux-interview-questions-answers/ 15/20
1/25/2020 Top 48 Linux Interview Questions & Answers (Updated 2020)
4) lsof command
lsof is a command line utility which is used to list the information about the les that are
opened by various processes. In unix, everything is a le: pipes, sockets, directories,
devices, etc. So by using lsof (https://linoxide.com/how-tos/lsof-command-list-process-id-
information/), you can get the information about any opened les.
# lsof /var/log/syslog
# lsof -u username
# lsof -i
List all network les in use by a speci c process
https://linoxide.com/linux-how-to/linux-interview-questions-answers/ 16/20
1/25/2020 Top 48 Linux Interview Questions & Answers (Updated 2020)
# lsof -i -a -c ssh
# lsof -i :25
5) grep command
Grep is a command used to search text or for a given le for lines containing a match to the
given strings or words. By default, grep displays the matching lines
(https://linoxide.com/how-tos/linux-grep-command- nd-strings/).
On IP-based virtual hosting, we can run more than one web site on the same server
we
machine, but each web site has its own IP address while In Name-based virtual hosting,
host multiple websites on the same IP address. But for this to succeed, you have to put
more than one DNS record for your IP address in the DNS database.
https://linoxide.com/linux-how-to/linux-interview-questions-answers/ 17/20
1/25/2020 Top 48 Linux Interview Questions & Answers (Updated 2020)
The swappiness parameter controls the tendency of the kernel to move processes out of
physical memory and onto the swap disk. Because disks are much slower than RAM, this
can lead to slower response times for system and applications if processes are too
aggressively moved out of memory.
swappiness can have a value of between 0 and 100
https://linoxide.com/linux-how-to/linux-interview-questions-answers/ 18/20
1/25/2020 Top 48 Linux Interview Questions & Answers (Updated 2020)
swappiness=0 tells the kernel to avoid swapping processes out of physical memory for as
long as possible
swappiness=100 tells the kernel to aggressively swap processes out of physical memory
and move them to swap cache
Conclusion
In this tutorial, we have explained the top expected interview questions for a Linux job.
Apart from these questions, you should be prepared to explain daily Linux tasks, projects,
some critical situations you have faced. Good luck!!
Read Also:
Ansible Interview Questions & Answers for Devops (https://linoxide.com/devops/ansible-
interview-questions-answers-for-devops/)
30 Expected DevOps Interview Questions and Answers (https://linoxide.com/linux-how-
to/devops-interview-questions-answers/)
70 Shell Scripting Interview Questions & Answers (https://linoxide.com/linux-shell-script/shell-
scripting-interview-questions-answers/)
Comments
Your email address will not be published. Required elds are marked *
Name * Email *
https://linoxide.com/linux-how-to/linux-interview-questions-answers/ 19/20
1/25/2020 Top 48 Linux Interview Questions & Answers (Updated 2020)
https://linoxide.com/linux-how-to/linux-interview-questions-answers/ 20/20