Here we have mentioned most frequently asked Linux Interview Questions and Answers specially for freshers and experienced.
1. What is Linux?
Ans:
Linux is an operating system based on UNIX and was first introduced by Linus Torvalds. It is based on the Linux Kernel and can run on different hardware platforms manufactured by Intel, MIPS, HP, IBM, SPARC, and Motorola. Another popular element in Linux is its mascot, a penguin figure named Tux.
2. What is the difference between UNIX and LINUX?
Ans:
Unix is originally began as a propriety operating system from Bell Laboratories, which later on spawned into different commercial versions. On the other hand, Linux is free, open source and intended as a non-propriety operating system for the masses.
3. What is BASH?
Ans:
BASH is short for Bourne Again SHell. It was written by Steve Bourne as a replacement to the original Bourne Shell (represented by /bin/sh). It combines all the features from the original version of Bourne Shell, plus additional functions to make it easier and more convenient to use. It has since been adapted as the default shell for most systems running Linux.
4. What is Linux Kernel?
Ans:
The Linux Kernel is a low-level systems software whose main role is to manage hardware resources for the user. It is also used to provide an interface for user-level interaction.
5. What is LILO?
Ans:
LILO is a boot loader for Linux. It is used mainly to load the Linux operating system into main memory so that it can begin its operations.
6. What is a swap space?
Ans:
Swap space is a certain amount of space used by Linux to temporarily hold some programs that are running concurrently. This happens when RAM does not have enough memory to hold all programs that are executing.
7. What is the advantage of open source?
Ans:
Open source allows you to distribute your software, including source codes freely to anyone who is interested. People would then be able to add features and even debug and correct errors that are in the source code. They can even make it run better and then redistribute these enhanced source code freely again. This eventually benefits everyone in the community.
8. What are the basic components of Linux?
Ans:
Just like any other typical operating system, Linux has all of these components: kernel, shells and GUIs, system utilities, and an application program. What makes Linux advantageous over other operating system is that every aspect comes with additional features and all codes for these are downloadable for free.
9. Does it help for a Linux system to have multiple desktop environments installed?
Ans:
In general, one desktop environment, like KDE or Gnome, is good enough to operate without issues. It’s all a matter of preference for the user, although the system allows switching from one environment to another. Some programs will work on one environment and not work on the other, so it could also be considered a factor in selecting which environment to use.
10. What is the basic difference between BASH and DOS?
Ans:
The key differences between the BASH and DOS console lies in 3 areas:
– BASH commands are case sensitive while DOS commands are not;
– under BASH, / character is a directory separator and \ acts as an escape character. Under DOS, / serves as a command argument delimiter and \ is the directory separator
– DOS follows a convention in naming files, which is 8 character file name followed by a dot and 3 character for the extension. BASH follows no such convention.
11. What is the importance of the GNU project?
Ans:
This so-called Free software movement allows several advantages, such as the freedom to run programs for any purpose and freedom to study and modify a program to your needs. It also allows you to redistribute copies of a software to other people, as well as the freedom to improve software and have it released for the public.
12. Describe the root account.
Ans:
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.
13. What is CLI?
Ans:
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 of using GUI find it difficult to remember commands including attributes that come with it.
14. What is GUI?
Ans:
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.
15. How do you open a command prompt when issuing a command?
Ans:
To open the default shell (which is where the command prompt can be found), press Ctrl-Alt-F1. This will provide a command line interface (CLI) from which you can run commands as needed.
16. How can you find out how much memory Linux is using?
Ans:
From a command shell, use the “concatenate” command: cat /proc/meminfo for memory usage information. You should see a line starting something like Mem: 64655360, etc. This is the total memory Linux thinks it has available to use.
You can also use commands
free – m
vmstat
top
htop
to find current memory usage
17. What is a typical size for a swap partition under a Linux system?
Ans:
The preferred size for a swap partition is twice the amount of physical memory available on the system. If this is not possible, then the minimum size should be the same as the amount of memory installed.
18. What are symbolic links?
Ans:
Symbolic links act similarly to shortcuts in Windows. Such links point to programs, files or directories. It also allows you instant access to it without having to go directly to the entire pathname.
19. Does the Ctrl+Alt+Del key combination work on Linux?
Ans:
Yes, it does. Just like Windows, you can use this key combination to perform a system restart. One difference is that you won’t be getting any confirmation message and therefore, a reboot is immediate.
20. How do you refer to the parallel port where devices such as printers are connected?
Ans:
Whereas under Windows you refer to the parallel port as the LPT port, under Linux you refer to it as /dev/lp . LPT1, LPT2 and LPT3 would therefore be referred to as /dev/lp0, /dev/lp1, or /dev/lp2 under Linux.
21. Are drives such as harddrive and floppy drives represented with drive letters?
Ans:
No. In Linux, each drive and device have different designations. For example, floppy drives are referred to as /dev/fd0 and /dev/fd1. IDE/EIDE hard drives are referred to as /dev/hda, /dev/hdb, /dev/hdc, and so forth.
22. How do you change permissions under Linux?
Ans:
Assuming you are the system administrator or the owner of a file or directory, you can grant permission using the chmod command. Use + symbol to add permission or – symbol to deny permission, along with any of the following letters: u (user), g (group), o (others), a (all), r (read), w (write) and x (execute). For example, the command chmod go+rw FILE1.TXT grants read and write access to the file FILE1.TXT, which is assigned to groups and others.
23. In Linux, what names are assigned to the different serial ports?
Ans:
Serial ports are identified as /dev/ttyS0 to /dev/ttyS7. These are the equivalent names of COM1 to COM8 in Windows.
24. How do you access partitions under Linux?
Ans:
Linux assigns numbers at the end of the drive identifier. For example, if the first IDE hard drive had three primary partitions, they would be named/numbered, /dev/hda1, /dev/hda2 and /dev/hda3.
25. What are hard links?
Ans:
Hard links point directly to the physical file on disk, and not on the path name. This means that if you rename or move the original file, the link will not break since the link is for the file itself, not the path where the file is located.
26. What is the maximum length for a filename under Linux?
Ans:
Any filename can have a maximum of 255 characters. This limit does not include the path name, so therefore the entire pathname and filename could well exceed 255 characters.
27. What are filenames that are preceded by a dot?
Ans:
In general, filenames that are preceded by a dot are hidden files. These files can be configuration files that hold important data or setup info. Setting these files as hidden makes it less likely to be accidentally deleted.
28. Explain virtual desktop.
Ans:
This serves as an alternative to minimizing and maximizing different windows on the current desktop. Using virtual desktops can clear the desktop when you can open one or more programs. Rather than minimizing/restoring all those programs as needed, you can simply shuffle between virtual desktops with programs intact in each one.
29. How do you share a program across different virtual desktops under Linux?
Ans:
To share a program across different virtual desktops, in the upper left-hand corner of a program window look for an icon that looks like a pushpin. Pressing this button will “pin” that application in place, making it appear in all virtual desktops, in the same position onscreen.
30. What does a nameless (empty) directory represent?
Ans:
This empty directory name serves as the nameless base of the Linux file system. This serves as an attachment for all other directories, files, drives, and devices.
31. What is the pwd command?
Ans:
The pwd command is short for print working directory command. Its counterpart in DOS is the cd command, and is used to display the current location in the directory tree.
32. What are daemons?
Ans:
Daemons are services that provide several functions that may not be available under the base operating system. Its main task is to listen for service request and at the same time to act on these requests. After the service is done, it is then disconnected and waits for further requests.
33. How do you switch from one desktop environment to another, such as switching from KDE to Gnome?
Ans:
Assuming you have these two environments installed, just log out from the graphical interface. Then at the login screen, type your login ID and password and choose which session type you wish to load. This choice will remain your default until you change it to something else.
34. What are the kinds of permissions under Linux?
Ans:
There are 3 kinds of permissions under Linux:
– Read: users may read the files or list the directory
– Write: users may write to the file of new files to the directory
– Execute: users may run the file or lookup a specific file within a directory
35. How does case sensitivity affect the way you use commands?
Ans:
When we talk about case sensitivity, commands are considered identical only if every character is encoded as is, including lowercase and uppercase letters. This means that CD, cd, and Cd are three different commands. Entering a command using uppercase letters, where it should be in lowercase, will produce different outputs.
36. What are environmental variables?
Ans:
Environmental variables are global settings that control the shell’s function as well as that of other Linux programs. Another common term for environmental variables is global shell variables.
37. What are the different modes when using vi editor?
Ans:
There are 3 modes under vi:
– Command mode – this is the mode where you start in
– Edit mode – this is the mode that allows you to do text editing
– Ex mode – this is the mode wherein you interact with vi with instructions to process a file
38. Is it possible to use shortcuts for a long pathname?
Ans:
Yes, there is. A feature known as filename expansion allows you do this using the TAB key. For example, if you have a path named /home/iceman/assignments directory, you would type as follows: /ho[tab]/ice[tab]/assi[tab] . This, however, assumes that the path is unique and that the shell you’re using supports this feature.
39. What is redirection?
Ans:
Redirection is the process of directing data from one output to another. It can also be used to direct an output as an input to another process.
40. What is grep command?
Ans:
grep a search command that makes use of pattern-based searching. It makes use of options and parameters that is specified along the command line and applies this pattern into searching the required file output.
41. What could possibly be the problem when a command that was issued gave a different result from the last time it was used?
Ans:
One highly possible reason for getting different results from what seems to be the same command has something to do with case sensitivity issues. Since Linux is case sensitive, a command that was previously used might have been entered in a different format from the present one. For example, to lists all files in the directory, you should type the command ls, and not LS. Typing LS would either result in an error message if there is no program by that exact name exist, or may produce a different output if there is a program named LS that performs another function.
42. What are the contents in /usr/local?
Ans:
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.
43. How do you terminate an ongoing process?
Ans:
Every process in the system is identified by a unique process id or pid. Use the kill command followed by the pid in order to terminate that process. To terminate all process at once, use kill 0.
44. What is command grouping and how does it work?
Ans:
You can use parentheses to group commands. For example, if you want to send the current date and time along with the contents of a file named OUTPUT to a second file named MYDATES, you can apply command grouping as follows: (date cat OUTPUT) > MYDATES
45. How do you execute more than one command or program from a single command line entry?
Ans:
You can combine several commands by separating each command or program using a semicolon symbol. For example, you can issue such a series of commands in a single entry:
ls –l cd .. ls –a MYWORK which is equivalent to 3 commands: ls -l cd.. ls -a MYWORK
**Note that this will be executed one after the other, in the order specified.
46. How do you insert comments in the command line prompt?
Ans:
Comments are created by typing the # symbol before the actual comment text. This tells the shell to completely ignore what follows. For example “# This is just a comment that the shell will ignore.”
47. Write a command that will look for files with an extension “c”, and has the occurrence of the string “apple” in it.
Ans:
Find ./ -name “*.c” | xargs grep –i “apple”
48. Write a command that will display all .txt files, including its individual permission.
Ans:
ls -al *.txt
49. Write a command that will do the following:
Ans:
-look for all files in the current and subsequent directories with an extension c,v
-strip the,v from the result (you can use sed command)
-use the result and use a grep command to search for all occurrences of the word ORANGE in the files.
Find ./ -name “*.c,v” | sed ‘s/,v//g’ | xargs grep “ORANGE”
50. What, if anything, is wrong with each of the following commands?
a) ls -l-s
b) cat file1, file2
c) ls – s Factdir
Ans:
a) there should be space between the 2 options: ls -l -s
b) do not use commas to separate arguments: cat file1 file2
c) there should be no space between hyphen and option label: ls –s Factdir
51. What is the command to calculate the size of a folder?
Ans:
To calculate the size of a folder uses the command du –sh folder1.
52. How can you find the status of a process?
Ans:
Use the command
ps ux
53. How can you check the memory status?
Ans:
You can use the command
free -m to display output in MB
free -g to display output in GB
54. Explain how to color the Git console?
Ans:
To color the Git console, you can use the command git config—global color.ui auto. In the command, the color.ui variable sets the default value for a variable such as color.diff and color.grep.
55. How can you append one file to another in Linux?
Ans:
To append one file to another in Linux you can use command cat file2 >> file 1. The operator >> appends the output of the named file or creates the file if it is not created. While another command cat file 1 file 2 > file 3 appends two or more files to one.
56. Explain how you can find a file using Terminal?
Ans:
To find a file you have to use a command, find . –name “process.txt” . It will look for the current directory for a file called process.txt.
57. Explain how you can create a folder using Terminal?
Ans:
To create a folder, you have to use command mkdir. It will be something like these: ~$ mkdir example
58. Explain how you can view the text file using Terminal?
Ans:
To view the text file, go to the specific folder where the text files are located by using the command cd and then type less filename.txt.
59. Explain how to enable curl on Ubuntu LAMP stack?
Ans:
To enable curl on Ubuntu, first, install libcurl, once done use following command sudo/etc/init .d /apache2 restart or sudo service apache2 restart.
60. Explain how to enable root loging in Ubuntu?
Ans:
The command which enables root loging is
#sudo sh-c ‘echo “greater-show-manual-login=true” >>/etc/lightdm/lightdm.conf’
61. How you can run a Linux program in the background simultaneously when you start your Linux Server?
Ans:
By using nohup. It will stop the process receiving the NOHUP signal and thus terminating it you log out of the program which was invoked with. & runs the process in the background.
62. Explain how to uninstall the libraries in Linux?
Ans:
To uninstall the libraries in Linux, you can use command sudo apt-get remove library_name
63. Linux Vs Windows
Ans:
LINUX | WINDOWS |
Linux is available for free | Windows has to be bought |
It is an open source OS | It is not open source OS |
One can customize Linux | No customizations available |
Provides high level security | Cannot defend virus and malware attacks |
Primary partitionig and logical partitioning available to boot | Booting available while primary partitioning only |
Back Slash separates directories | Forward slash separates directories |
File names are case particular | Irrespective of case while naming files |
64. How can I redirect both stderr and stdin at once?
Ans:
command > file.log 2>&1 : Redirect stderr to “where stdout is currently going”. In this case, that is a file opened in append mode. In other words, the &1reuses the file descriptor which stdout currently uses.
command 2>&1 | tee -a file.txt
65. What is the difference between /dev/random and /dev/urandom to generate random data?
Ans:
The Random Number Generator gathers environmental noise from device drivers and other sources into entropy pool. It also keeps an estimate of Number of bits of noise in entropy pool. It is from this entropy pool, random numbers are generated.
/dev/random will only return Random bytes from entropy pool. If entropy pool is empty, reads to /dev/random will be blocked until additional environmental noise is gathered. This is suited to high-quality randomnesses, such as one-time pad or key generation.
/dev/urandom will return as many random bytes as requested. But if the entropy pool is empty, it will generate data using SHA, MD5 or any other algorithm. It never blocks the operation. Due to this, the values are vulnerable to theoretical cryptographic attack, though no known methods exist.
For cryptographic purposes, you should really use /dev/random because of nature of data it returns. Possible waiting should be considered as an acceptable tradeoff for the sake of security, IMO. When you need random data fast, you should use /dev/urandom of course.
Both /dev/urandom and /dev/random are using the exact same CSPRNG (a cryptographically secure pseudorandom number generator). They only differ in very few ways that have nothing to do with “true” randomness and /dev/urandom is the preferred source of cryptographic randomness on UNIX-like systems.
66. How to recover from a chmod -R 000 /bin?
Ans:
If the chmod binary was set to 000, how would you fix it? You can face a problem with /bin/chmod permission denied so you will be not able to apply for permissions. There is a method to recover it by reinstalling coreutils
# ls -ls /bin/chmod
60 -rwxr-xr-x 1 root root 58584 Nov 5 20:46 /bin/chmod
# chmod 000 /bin/chmod
# ls -ls /bin/chmod
60 ———- 1 root root 58584 Nov 5 20:46 /bin/chmod
# uname -a
Linux centos-01 3.10.0-514.6.1.el7.x86_64 #1 SMP Wed Jan 18 13:06:36 UTC 2017 x86_64 x86_64 x86_64 GNU/Linux
# rpm –query centos-release
centos-release-7-3.1611.el7.centos.x86_64
[root@centos-01 ~]# ls -l
total 12
drwxr-xr-x 2 root root 4096 Apr 6 22:54 linox
drwxr-xr-x 2 root root 4096 Apr 6 22:54 pac
drwxr-xr-x 2 root root 4096 Apr 6 22:54 utils
# chmod 640 linox
-bash: /usr/bin/chmod: Permission denied
# wget http://mirror.centos.org/centos/7/os/x86_64/Packages/coreutils-8.22-18.el7.x86_64.rpm
–2017-04-06 23:23:44– http://mirror.centos.org/centos/7/os/x86_64/Packages/coreutils-8.22-18.el7.x86_64.rpm
Resolving mirror.centos.org (mirror.centos.org)… 204.15.73.245, 2604:eb80:1:4::10
Connecting to mirror.centos.org (mirror.centos.org)|204.15.73.245|:80… connected.
HTTP request sent, awaiting response… 200 OK
Length: 3412144 (3.3M) [application/x-rpm]
Saving to: ‘coreutils-8.22-18.el7.x86_64.rpm’
100%[============================================================================================================>] 3,412,144 4.84MB/s in 0.7s
2017-04-06 23:23:45 (4.84 MB/s) – ‘coreutils-8.22-18.el7.x86_64.rpm’ saved [3412144/3412144]
# rpm -Uvh –force coreutils-8.22-18.el7.x86_64.rpm
Preparing… ################################# [100%]
Updating / installing…
1:coreutils-8.22-18.el7 ################################# [100%]
# ls -ls /bin/chmod
60 -rwxr-xr-x 1 root root 58584 Nov 5 20:46 /bin/chmod
# chmod 640 linox
# ls -ls
total 3348
3336 -rw-r–r– 1 root root 3412144 Nov 20 17:26 coreutils-8.22-18.el7.x86_64.rpm
4 drw-r—– 2 root root 4096 Apr 6 22:54 linox
4 drwxr-xr-x 2 root root 4096 Apr 6 22:54 pac
4 drwxr-xr-x 2 root root 4096 Apr 6 22:54 utils
Reinstalling coreutils also works on Apt based systems.
67. What is the difference between tar and zip ?
Ans:
Sometimes sysadmins Linux need to save data safety and to this, it is recommended to compress the data. We have some methods or commands for compression on Linux. So frequently asked questions could be why should I use this command instead of another one example, why should I use tar instead of zip. To answer this, you should know the difference between the two.
tar is only an archiver whereas zip is an archiver and compressor. Tar uses gzip and bzip2 to achieve compression. With using tar command, we preserve metadata information of file and directories like seiuid, setgid and sticky bitinformation which are very important while zip doesn’t preserve theses information. It is very important for criticals information. Other advantages of using tar is the fact that it assembles all the files into a single file to compress directly while zip compress file by file.
68. How to check open ports on a remote server without netcat or nmap linux command?
Ans:
In the work of sysadmin, we can sometimes want to check open ports on our remote server. But if we are on a machine where can not install nmap or we don’t have the possibility to install a tool which can help us to check open ports, what could we do?
We can check it with bash using /dev/tcp or /dev/udp to open a TCP or UDP connection to the associated socket. The command behavior is:
$ echo > /dev/tcp/$host/$port
we can associate a message to display if the port is opened
$ echo > /etc/tcp/8.8.8.8/53 && echo “OPEN PORT”
OPEN PORT
$ echo > /dev/tcp/8.8.8.8/80 && echo “GOOD” || echo “NOT OPEN”
-bash: connect: Connection timed out
-bash: /dev/tcp/8.8.8.8/80: Connection timed out
NOT OPEN
69. systemd over init system, What do you think?
Ans:
Systemd is well designed. It was conceived from the top, not just to fix bugs, but to be a correct implementation of the base system services. A systemd, may refer to all the packages, utilities and libraries around daemon. It was designed to overcome the shortcomings of init. It itself is a background process which is designed to start processes in parallel, thus reducing the boot time and computational overhead. It has a lot other features as compared to init while Sysvinit was never designed to cope with the dynamic/event-based architecture of the current Linux kernel. The only reason why we still use it today is the cost of a migration.
Systemd ships a growing number of useful, unified command-line interfaces for system settings and control (timedatectl, bootctl, hostnamectl, loginctl, machinectl, kernel-install, localectl). In Debian, they use the existing configuration files without breaking compatibility.
Systemd makes the boot process much simpler, entirely removing the need to specify dependencies in many cases thanks to D-Bus activation, socket activation, file/inotify activation and udev integration.
Systemd supports SELinux integration while SysV doesn’t
Systemd can handle the boot process from head to toe, without needing to use any of the existing shell scripts. Systemd extends the logging features of the system in many ways with journald, and can remain integrated with the existing rsyslog daemon. Logs are in a structured format, attributed to filename, line of code, PID and service. They include the early boot (starting from initramfs). They can be quickly filtered and programmatically accessed through an efficient interface.
Systemd unit files, unlike SysV scripts, can usually be shipped by upstream, or at least shared with other distributions (already more than 1000 existing unit files in Fedora) without any changes, the Debian specifics being handled by systemd itself.
Systemd is incredibly fast (1 second to boot). It was not designed with speed in mind, but doing things correctly avoids all the delays currently incurred by the boot process.
The transition plan is easy, since existing init scripts are treated as first-class services: scripts can depend (using LSB headers) on units, units can depend on scripts. More than 99% of init scripts can be used without a modification.
It is not just init. It unifies, in fewer lines of code, everything that is related to starting services and managing session groups: user login, cron jobs, network services (inetd), virtual TTY management… Having a single system to handle all of that allows us to remove a lot of cruft, and to use less memory on the system.
70. What basics measures could you take to secure an ssh connection?
Ans:
For Linux sysadmins, it is frequent to access servers by ssh. But are we sure the communication established is really good secured? There some additionals very simple steps that can be taken to initially harden the SSH service, such as:
Disabling root login, and even password-based logins will further reinforce the security of the server.
Disabling password-based logins and allow key based logins which are secured but can be taken further by restricting their use from only certain IP addresses.
Changing the standard port to something other significantly decreases random brute force attempts from the internet
Forcing the service to use only version 2 of the protocol will introduce both security and feature enhancement.
The whitelist approach can be taken, where only the users that belong to a certain list can log in via SSH to the server.
71. What is LVM and does it required on Linux servers?
Ans:
LVM is a logical volume manager. It requires to resize filesystem size. This size can be extended and reduced using lvextend and lvreduce commands respectively. You can think of LVM as dynamic partitions, meaning that you can create/resize/delete LVM partitions from the command line while your Linux system is running: no need to reboot the system to make the kernel aware of the newly-created or resized partitions. LVM also provides:
You can extend over more than one disk if you have more than one hard-disk. They are not limited by the size of one single disk, rather by the total aggregate size.
You can create a (read-only) snapshot of any LV (Logical Volume). You can revert the original LV to the snapshot at a later time, or delete the snapshot if you no longer need it. This is handy for server backups for instance (you cannot stop all your applications from writing, so you create a snapshot and backup the snapshot LV), but can also be used to provide a “safety net” before a critical system upgrade (clone the root partition, upgrade, revert if something went wrong).
you can also set up writeable snapshots too. It allows you to freeze an existing Logical Volume in time, at any moment, even while the system is running. You can continue to use the original volume normally, but the snapshot volume appears to be an image of the original, frozen in time at the moment you created it. You can use this to get a consistent filesystem image to back up, without shutting down the system. You can also use it to save the state of the system, so that you can later return to that state if you mess things up. You can even mount the snapshot volume and make changes to it, without affecting the original.
72. What is umask and how can it be helpful on linux server?
Ans:
When user create a file or directory under Linux or UNIX, it created with a default set of permissions. In most case, the system defaults may be open or relaxed for file sharing purpose. The user file-creation mode mask (umask) is used to determine the file permission for newly created files. It can be used to control the default file permission for new files.
It acts as a set of permissions that applications cannot set on files. It’s a file mode creation mask for processes and cannot be set for directories itself. Most applications would not create files with execute permissions set, so they would have a default of 666, which is then modified by the umask.
As you have set the umask to remove the read/write bits for the owner and the read bits for others, a default such as 777 in applications would result in the file permissions being 133. This would mean that you (and others) could execute the file, and others would be able to write to it.
If you want to make files not be read/write/execute by anyone but the owner, you should use a umask like 077 to turn off those permissions for the group & others.
The default umask on Ubuntu is 0022 which means that newly created files are readable by everyone, but only writable by the owner:
# umask
0022
# touch file
# ls -l
total 3340
-rw-r–r– 1 root root 3412144 Nov 20 17:26 coreutils-8.22-18.el7.x86_64.rpm
-rw-r–r– 1 root root 0 Apr 7 04:00 file
# umask 133
# umask
0133
# touch new-file
# ls -l
total 3336
-rw-r–r– 1 root root 3412144 Nov 20 17:26 coreutils-8.22-18.el7.x86_64.rpm
-rw-r–r– 1 root root 0 Apr 7 04:00 file
-rw-r–r– 1 root root 0 Apr 7 04:00 new-file
73. There is two command to schedule automated task, why should I use cron instead of anacron? What is the difference between the two?
Ans:
When we schedule task in cron jobs, we have the possibility to use cron and anacron. But there is a frequently asked question which should be and what are the particularity of the two commands?
Both cron and anacron are daemons that can schedule execution of recurring tasks to a certain point in time defined by the user. The main difference between cron and anacron is that the former assumes that the system is running continuously. If your system is off and you have a job scheduled during this time, the job never gets executed.
On the other hand anacron is ‘anachronistic’ and is designed for systems that are not running 24×7. For it to work anacron uses time-stamped files to find out when the last time its commands were executed. It also maintains a file /etc/anacrontab just like cron does. In addition, cron.daily runs anacron everyhour. Also, anacron can only run a job once a day, but cron can run as often as every minute so
cron gives minimum granularity in minute while Anacron gives it in days
Cron job can be scheduled by any normal user while Anacron can be scheduled only by the super user (the superuser is a special user account used for system administration.
Cron expects the system to be up and running while the Anacron doesn’t expect the system to be up and running all the time. In case of Anacron, if a job is scheduled and the system is down that time, it will execute the job as soon as the system is up and running so cron is ideal for servers while anacron is ideal for desktops and laptops.
cron should be used when you want a job to be executed at a particular hour and minute while Anacron should be used in when the job can be executed irrespective of the hour and minute.
74. What is an inode?
Ans:
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 file was modified, file owner, file permissions, size of file, device ID, uid of the file, etc. This type of information is key to a file 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 file 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 files 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 file system is installed and when it does its initial structuring. So this way we can see that in a file system, the aximum number of Inodes and hence maximum number of files are set. Now, the above concept brings up another interesting fact. A file system can run out of space in two ways:
No space for adding new data is left
All the Inodes are consumed.
To get a listing of an inode number, 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
/root/new-file
75. When you get a “filesystem is full” error, but ‘df’ shows there is free space, what is the problem?
Ans:
It is possible that we have free storage space but still we cannot add any new data in file system because all the Inodes are consumed. the df -i command will show that. This may happen in a case where file system contains very large number of very small sized files. This will consume all the Inodes and though there would be free space from a Hard-disk-drive point of view but from file system point of view no Inode available to store any new file.
A storage unit can contain numerous small files. Each file takes up 128 bytes of the inode structure. If the inode structure fills up before the data storage of the disk, no more files can be copied to the disk. Once inode storage is freed in the structure, the storage unit can have files written to it again.
# touch test-file
touch: cannot touch ‘test’: no space left on device
# df -Th
Filesystem Type Size Used Avail Use% Mounted onFilesystem
udev devtmpfs 3.9G 0 3.9G 0% /dev
tmpfs tmpfs 788M 10M 778M 2% /run
/dev/sda6 ext4 44G 24G 18G 59% /
/dev/sda7 ext4 103G 74G 24.0G 71% /home
/dev/sda2 vfat 95M 29M 67M 31% /boot/efi
# df -i
Filesystem Inodes IUsed IFree IUse% Mounted on
udev 1002898 650 1002248 1% /dev
tmpfs 1008079 1128 1006951 1% /run
/dev/sda6 2875392 617635 2257757 22% /
/dev/sda7 6815744 80342 6735402 100% /home
76. What is the difference between Linux and UNIX?
Ans:
UNIX – Only big companies are allowed to use the UNIX copyright and name. IBM AIX, Sun Solaris, and HP-UX all are UNIX operating systems. Most UNIX operating systems are commercial in nature.
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.
License and cost
Linux is Free. You can download it from the Internet or redistribute it under GNU licenses. Most UNIX like operating systems are not free.
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.
77. What are Linux file systems?
Ans:
By default, Linux supports and use ext3 or ext4 file systems. UNIX supports file systems like jfs, gpfs (AIX), jfs, gpfs (HP-UX), jfs, gpfs (Solaris).
78. What are System Startup Scripts?
Ans:
By default, Linux and UNIX come with system initialization script but they are located in different directories:
HP-UX – /sbin/init.d
AIX – /etc/rc.d/init.d
Linux – /etc/init.d
79. What are the some UNIX Operating System Names?
Ans:
Some of the most used UNIX operating systems are:
HP-UX
IBM AIX
Sun Solairs
Mac OS X
IRIX
80. What are the Linux Distribution (Operating System) Names?
Ans:
Here are the some Linux operating system names:
Redhat Enterprise Linux
Fedora Linux
Debian Linux
Suse Enterprise Linux
Ubuntu Linux
81. What are some common things between Linux & UNIX?
Ans:
Both Linux and UNIX share many common applications such as:
GUI, file, and windows managers (KDE, Gnome)
Shells (ksh, csh, bash)
Various office applications such as OpenOffice.org
Development tools like perl, php, python, GNU c/c++ compilers
Posix interface
82. What does curl command do in Linux?
Ans:
In Linux, curl command is used to test an application’s endpoint or connectivity to an upstream service endpoint. curl command will be used to determine if the application can reach another service, like a database, or checking if your service is healthy.
curl Example:
$ curl -I -s myapplication:5000
HTTP/1.0 500 INTERNAL SERVER ERROR
This example through an exception saying that your application can’t reach your server.
In the above command, the -I option shows the header information and the -s option silences the response body.
83. What is ls command and what it does?
Ans:
ls lists files in a directory. In Linux System admins and developers uses this command very often. In containers, ls command can help determine your container image’s directory and files.
ls Example:
$ ./myapp
bash: ./myapp: Permission denied
$ ls -l myapp
-rw-r–r–. 1 root root 33 Dec 17 15:27 myapp
84. What is tail command in Linux?
Ans:
tail command displays the last part of a file. Generally, users don’t need every log line to troubleshoot. Instead, you want to check what your logs say about the most recent request to your application.
tail Example:
$ tail -n 100 /var/log/httpd/access_log
85. What is cat command in Linux?
Ans:
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 Example:
$ cat requirements.txt
flask
flask_pymongo
86. What is grep command in Linux?
Ans:
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.
grep Example:
$ 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 in 681 ms
87. What is ps command in Linux?
Ans:
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
88. What is env command in Linux?
Ans:
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:
$ env
PYTHON_PIP_VERSION=9.0.1
HOME=/root
DB_NAME=test
PATH=/usr/local/bin:/usr/local/sbin
LANG=C.UTF-8
PYTHON_VERSION=3.4.6
PWD=/
DB_URI=mongodb://database:27017/test
89. What is top Command in Linux?
Ans:
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.
90. What is netstat command in Linux?
Ans:
netstat command in Linux shows the network status. This netstat command shows network ports in use and their incoming connections.
91. What is lsof command in Linux?
Ans:
lsof command lists the open files associated with your application.
92. What is df command in Linux?
Ans:
Users can use df command to troubleshoot disk space issues. Here df stands for display free disk space.
df Command Example:
df -h
93. What is du command in Linux?
Ans:
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/*
1.8M /var/log/anaconda
384K /var/log/audit
4.0K /var/log/boot.log
0 /var/log/chrony
4.0K /var/log/cron
4.0K /var/log/maillog
64K /var/log/messages
94. What is iptables command in Linux?
Ans:
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.
95. What does cd – command do?
Ans:
cd- command go to the previous directory.
96. What does cd command do?
Ans:
Go to $HOME directory
97. What does (cd dir && command) do?
Ans:
cd dir && command goes to the dir, execute the command and return to the current directory.
98. What does pushd command do?
Ans:
pushhd command put current dir on stack so you can pop back to it.
99. What is ls -lSr command?
Ans:
ls – ISr command shows files by size, biggest file will be displayed last.
100. What is du -s * | sort -k1,1rn | head command used for?
Ans:
This command shows top disk users in current dir.
101. What does this du -hs /home/* | sort -k1,1h command do?
Ans:
This command sort path by easy to interpret disk usage.
102. What is df -h command?
Ans:
This command show free space on mounted file systems.
103. What is df -i command?
Ans:
df -i command shows free inodes on mounted filesystems.
104. What is fdisk -l command used for?
Ans:
fdisk -I command show disks partitions sizes and types (run as root).
105. How do you kill program using one port in Linux?
Ans:
Use this command to kills the program using one port: sudo fuser -k 8000/tcp
106. How do you limit memory usage for commands?
Ans:
ulimit -Sv 1000 # 1000 KBs = 1 MB
ulimit -Sv unlimited # Remove limit
107. How do you get full path of a file in Linux?
Ans:
Use this command: readlink -f file.txt
108. How do you list contents of tar.gz and extract only one file?
Ans:
Use these commands:
tar tf file.tgz
tar xf file.tgz filename
109. How do you find who is logged in?
Ans:
Use this command to find who logged in: w
110. How do you check permissions of each directory to a file?
Ans:
It is useful to detect permissions errors, for example when configuring a web server.
namei -l /path/to/file.txt
111. How do you run command every time a file is modified?
Ans:
Use this command to do:
while inotifywait -e close_write document.tex
do
make
done
112. How to copy text to clipboard?
Ans:
Use this command: cat file.txt | xclip -selection clipboard
113. How do you check resources usage?
Ans:
Use this command to check resource usage: /usr/bin/time -v ls
114. How do you run a command for a limited time?
Ans:
Use this command: timeout 10s ./script.sh
# Restart every 30 minutes
while true; do timeout 30m ./script.sh; done
115. How do you combine two lines from two sorted files in Linux?
Ans:
Use this command: comm file1 file2.
List of Other Linux Courses:
Red Hat Certified Engineer | Linux Security Fundamentals |
Linux Networking | Linux Administration |
Linux Cluster | IBM LinuxONE |
116. What is Linux and why is it so popular?
Ans:
Linux is an operating system that uses UNIX like Operating system. However, unlike UNIX, Linux is an open source and free software. Linux was originally created by Linus Torvalds and commonly used in servers.
Popularity of Linux is because of the following reasons
– It is free and open source. We can download Linux for free and customize it as per our needs.
– It is very robust and adaptable.
– Immense amount of libraries and utilities
117. What is Linux and why is it so popular?
Ans:
Linux is a multiuser, multitask GUI based open source operating system developed by Linus Torvalds Torvalds has invited the community to enhance the Linux kernel and thousands of system programmers worked on to enhance.
Prior to Linux, there is UNIX. The desktop work stations from various companies were based on UNIX. Later a numerous companies entered and each one of them had their own UNIX version. As the proprietary authority is owned by each company and the lack of central authority weaken UNIX. As Linux is free and runs on any PC platform it gained the popularity very quickly. The following are few more reasons for its popularity:
– People who are familiar with UNIX can work on Linux with ease and comfort.
– People who want great control over network security and on operating system
118. Linux LILO – What is LILO?
Ans:
LILO is Linux Loader is a boot loader for Linux. It is used to load Linux into the memory and start the Operating system.
119. Linux – Difference between home directory and working directory?
Ans:
Difference between home directory and working directory – Home directory is the default working directory when a user logs in. On the other hand, working directory is the user’s current directory.
120. Linux – Difference between internal and external commands
Ans:
Difference between internal and external commands – Internal commands are commands that are already loaded in the system. They can be executed any time and are independent.
121. What is Linux and also explain the basic components of Linux?
Ans:
Linux is the most commonly used operating system that is open source and free. For any computer, the operating system acts as the backbone, and it is most important software that is required for any computer. From network routers, television, video games console, smartwatches, smartphones, desktops, laptops to any other electronic device, Linux is everywhere.
Linux operating system is consist of 3 components which are as below:
Kernel: Linux is a monolithic kernel that is free and open source software that is responsible for managing hardware resources for the users.
System Library: System Library plays a vital role because application programs access Kernels feature using system library.
System Utility: System Utility performs specific and individual level tasks.
122. What are the differences between UNIX and Linux Operating System?
Ans:
To understand the differences between UNIX and Linux Operating system, first of all, we should know that Linux is a UNIX clone, the Kernel of which is created by Linus Torvalds. There are so many differences between Linux and UNIX operating system which are as follows:
Open Source Operating System:
The most significant difference between UNIX and Linux operating system is Linux is an open source operating system. The open-source operating system that means Linux source code is available for use so that developers can modify it as per their requirement. But UNIX operating system doesn’t come under the broad category of an open-source operating system for which developers can edit it.
Free of Cost:
One of the biggest reason that it is broadly used is Linux operating system is free of cost. Linux operating system is free, but UNIX Operating system is not free. We can download it from the internet.
Compatibility and Flexibility:
If we compare the flexibility and compatibility of both operating system, you will find that Linux is more flexible than UNIX operating system and more compatible with different types of hardware as compared to UNIX operating System.
123. Describe BASH.
Ans:
BASH stands for Bourne Again Shell. BASH is the UNIX shell for the GNU operating system. So, BASH is the command language interpreter that helps you to enter your input, and thus you can retrieve information. In a straightforward language, we can say that it is a program that will understand the data entered by the user and execute the command and gives output.
124. What is crontab and explain its functionality and explain the format of crontab?
Ans:
Cron is a scheduler that executes the commands at a regular interval as per the specific date and time defined. We have multiple users in Linux, and all the users can have their crontab separately. The crontabs files are saved at a particular location that is /var/spool/cron/crontabs.
There are six fields in the format for the crontab that is as below:
<command/program to execute>
125. What do you understand by CLI?
Ans:
CLI is an acronym for Command Line Interface. We have to provide the information to the computer so that it can perform the function accordingly. In Linux, CLI is the interface that provides the user an interface so that user can type the commands and it complete the tasks. CLI is very easy to use, but it should be typed very precisely.
Advanced Linux Interview Questions and Answers
Whenever you are going for a Linux interview, you can expect to be asked advanced level questions, so here we have explained some advanced level question for your Linux interview preparation.
126. Explain Network Bonding and also explain the different types of Network bonding?
Ans:
Network Bonding as the name implies that it is the process of bonding or joining two or more than two network interfaces to create one interface. It helps in improving the network throughput, bandwidth, redundancy, load balancing as in case any of the interfaces is down; the other one will continue to work. Several types of Network Bonding are available that are based on the kind of bonding method.
Below are the different bonding types in Linux:
balance-rr or mode 0 – This is the default mode of network bonding that works on the round-robin policy that means from the first slave to the last, and it is used for fault tolerance and load balancing.
active-backup or mode 1 – This type of network bonding works on the active-backup policy that means only one slave will be active and other will work just when another slave fails. This mode is also used for fault tolerance.
balance-xor or mode 2 –This type of network bonding sets an exclusive or mode that means source MAC address is XOR’d with the destination address, and thus it provides fault tolerance and load balancing.
broadcast or mode 3 –This mode sets a broadcast mode to provide fault tolerance, and it should be used for particular purposes. In this type of network bonding, all transmissions are sent to all slave interfaces.
802.3ad or mode 4 –This mode will create the aggregation groups, and all the groups will share the same speed. For this, mode sets an IEEE 802.3ad dynamic link aggregation mode. It is done by particular switch support that supports IEEE 802.3ad dynamic link.
balance-tlb or mode 5 –This mode sets a transmit load balancing mode for fault tolerance and load balancing and does not require any switch support.
balance-alb or mode 6 –This mode sets an active load balancing to achieve fault tolerance and load balancing.
127. What is the similarity and difference between cron and anacron? Which one would you prefer to use?
Ans:
Here we are going to discuss the similarity and the differences between cron and anacron. So, let’s start with the analogy:
Cron and Anacron are used to schedule the tasks in cron jobs. Both of these are the daemons that are used to schedule the execution of commands or tasks as per the information provided by the user.
Differences between cron and anacron:
One of the main difference between cron and anacron jobs is that cron works on the system that are running continuously that means it is designed for the system that is running24*7. While anacron is used for the systems that are not running continuously.
Other difference between the two is cron jobs can run every minute, but anacron jobs can be run only once a day.
Any normal user can do the scheduling of cron jobs, but the scheduling of anacron jobs can be done by the superuser only.
Cron should be used when you need to execute the job at a specific time as per the given time in cron, but anacron should be used in when there is no any restriction for the timing and can be executed at any time.
If we think about which one is ideal for servers or desktops, then cron should be used for servers while anacron should be used for desktops or laptops.
128. What is the issue behind getting an error “filesystem is full” while there is space available when you check it through “df” command? How will you rectify this problem?
Ans:
When all the inodes are consumed then even though you have free space, you will get the error that filesystem is full. So, to check whether there is space available, we have to use the command df –i. Sometimes, it may happen file system or storage unit contains the substantial number of small files, and each of the files takes 128 bytes of the inode structure then inode structure fills up, and we will not be able to copy any more file to the disk. So, to rectify the problem, you need to free the space in inode storage, and you will be able to save more files.
129. Where is password file located in Linux and how can you improve the security of password file?
Ans:
This is an important question that is generally asked by the interviewers. User information along with the passwords in Linux is stored in/etc/passwd that is a compatible format. But this file is used to get the user information by several tools. Here, security is at risk. So, we have to make it secured.
To improve the security of the password file, instead of using a compatible format we can use shadow password format. So, in shadow password format, the password will be stored as single “x” character which is not the same file (/etc/passwd). This information is stored in another file instead with a file name /etc/shadow. So, to enhance the security, the file is made word readable and also, this file is readable only by the root user. Thus security risks are overcome to a great extent by using the shadow password format.
130. What is Key-based authentication? Explain.
Ans:
There are various methods to enter into the servers. One of the ways to log in is using password-based authentication, but that is not secure. So, we need a method that is secured.
One of the ways to achieve the security is to use Key-based authentication. To use this type of authentication, we have to disable the password-based authentication. So, there is a procedure to set up this authentication which is as follows:
We have to get the SSH key pair using below command:
$ ssh-keygen -t rsa
It will generate the public/private rsa key pair.
Enter file where you want to save this generated key (/home/username/.ssh/id_rsa):
It will prompt you for the same location, i.e. ~/.ssh/id_rsa for the key pair. Press enter if you want to confirm the same location. Else, if you want to provide any other location, enter that and confirm the same.
Now copy ~/.ssh/id_rsa.pub into the ~/.ssh/authorized_keys that will be located where you have to connect.
Now, we have to provide the permissions to the file as per below command:
$ chmod 600 ~/.ssh/authorized_keys
Now try to sshthe machine you want to connect, and you will see that you are able to login to the machine without a password.
If you are confirmed that key-based authentication is working fine, disable the password-based authentication.
Go to the path /etc/ ssh/sshd_config
set the following property as no.
PasswordAuthentication no
131. Explain the logical steps to increase the size of LVM partition?
Ans:
Some logical steps need to be followed to increase the size of LVM partition. These are as follows:
Run the command as per given format:
lvextend -L +500M /dev/
Here, we are extending the size of LVM partition by 500MB.
resize2fs /dev/
You can check the size of partition using ‘df -h’ command
132. Using which utility you can create a partition from the raw disk?
Ans:
To create the partition from the raw disk, you have to use fdisk utility.Below are the steps to create a partition from the raw disk:
Step 1: Run the below command:
fdisk /dev/hd* (IDE) or /dev/sd* (SCSI)
Step 2: Type n to create a new partition
Step 3: Now partition has been created, and we have to write the changes to the partition table, so type w command to write the changes.
133. What are the default port numbers used for SMTP, FTP,DNS, DHCP, SSH?
Ans:
Service Port
SMTP 25
FTP 20 for data transfer and 21 for Connection established
DNS 53
DHCP 67/UDP(for DHCP server, 68/UDPfor DHCP client
SSH 22
134. How do you create a new user account and set the password for a user from a shell prompt in Linux?
Ans:
To create a new user account from a shell prompt follow the below steps:
Log in as root user if you are not logged in as root using su – command.
Enter the root user password
The useradd command is used to create a new user in Linux. So, type command useradd and give the username you want to create as given below:
Useradd smith
To set the password of the user smith type the command: passwd smith
It will prompt for the new password. Enter the new password for user smith.
It will ask to retype the password. So, retype the same password and password is set for the user.
135. Explain all the fields in the/etc/passwd file?
Ans:
/etc/passwd file contains the useful information for all the system users who log in. We have many fields in /etc/passwd file such as username, password, user ID, group ID, comment or user ID info, home directory, command /shell, etc. So, this file contains sensitive information regarding all the user accounts. There is a single line per user in this file. Colon (:) separates the fields in /etc/passwd. Below is the explanation of the fields.
Username: First field is the username that contains the username which is 1 to 32 length characters.
Password: This field does not show the actual password as the password is encrypted. Here, x character shows that password is encrypted that is located in /etc/shadow file.
User ID (UID): All the users created in Linux is given a user ID whenever the user is created. UID 0 is fixed and reserved for the root user.
Group ID (GID): This field specifies the name of the group to which the user belongs. The group information is also stored in a file /etc/group.
User ID Info: Here you can add comments and you can add any extra information related to the users like full name, contact number, etc.
Home directory: This field provides the path where the user is directed after the login. For example, /home/smith.
Command/shell: This field provides the path of a command/shell and denotes that user has access to this shell i.e. /bin/bash.
136. What is the advantage of executing the running processes in the background? How can you do that?
Ans:
The most significant advantage of executing the running process in the background is that you can do any other task simultaneously while other processes are running in the background. So, more processes can be completed in the background while you are working on different processes. It can be achieved by adding a special character ‘&’ at the end of the command.
137. List the differences between BASH and DOS?
Ans:
There are many differences between BASH and DOS that are as below:
Out of these two commands, BASH is case sensitive while DOS is not case sensitive.
In BASH ‘/’ acts the directory separator while in DOS ‘/’ acts as the command argument delimiter.
In BASH ‘\’ is used as the escape character while in DOS ‘\’ acts as the directory separator.
In BASH, there is a file convention used while in DOS, there is no any file convention used.
138. Explain system calls used for process management?
Ans:
There are some system calls used in Linux for process management. These are as follows:
Fork(): It is used to create a new process
Exec(): It is used to execute a new process
Wait(): It is used to make the process to wait
Exit(): It is used to exit or terminate the process
Getpid(): It is used to find the unique process ID
Getppid(): It is used to check the parent process ID
Nice(): It is used to bias the currently running process property
139. How can multiple machines share a single internet connection in Linux?
Ans:
Linux machine can be made as a router so that multiple devices can share a single internet connection. For this, we have to use a feature called “IP Masquerade.” This functionality will help to connect multiple computers to connect to the Linux machine as well as internet. This functionality will also allow those internal computers to connect who do not have IP addresses.
140. If a volume group already exists and we need to extend the volume group to some extent. How will you achieve this?
Ans:
Linux provide the facility to increase the size of a volume group even if it already exists. For this, we need to run a command.
First of all, we have to create a physical volume (/dev/sda1)
Size of the physical volume should be the size you want the size of the logical volume.
Now, run the below command:
vgextend VG1 /dev/sda1
Here VG1 is the name of the volume group.
141. What do you understand about Linux Kernel and can you edit it?
Ans:
Linux Kernel is the component that manages the hardware resources for the user and that provides essential services and interact with the user commands. Linux Kernel is an open source software and free, and it is released under General Public License so we can edit it and it is legal.
142. What are the different types of Kernels? Explain
Ans:
We can build kernels by many different types, but 3 of the types of kernels are most commonly used: monolithic, microkernel and hybrid.
Microkernel: This type of kernel only manages CPU, memory, and IPC. This kind of kernel provides portability, small memory footprint and also security.
Monolithic Kernel: Linux is a monolithic kernel. So, this type of kernel provides file management, system server calls, also manages CPU, IPC as well as device drivers. It provides easier access to the process to communicate and as there is not any queue for processor time, so processes react faster.
Hybrid Kernel: In this type of kernels, programmers can select what they want to run in user mode and what in supervisor mode. So, this kernel provides more flexibility than any other kernel but it can have some latency problems.
143. Explain Linux Boot Sequence.
Ans:
There are six levels of a Linux Boot Sequence. These are as follows:
BIOS: Full form of BIOS is Basic Input or Output System that performs integrity checks and it will search and load and then it will execute the bootloader.
MBR: MBR means Master Boot Record. MBR contains the information regarding GRUB and executes and loads this bootloader.
GRUB: GRUB means Grand Unified Bootloader. In case, many kernel images are installed on your system then you can select which one you want to execute.
Kernel: Root file system is mounted by Kernel and executes the /sbin/init program.
Init: Init checks the file /etc/inittab and decides the run level. There are seven-run levels available from 0-6. It will identify the default init level and will load the program.
Runlevel programs: As per your default settings for the run level, the system will execute the programs.
144. Explain Interrupts in Linux and also explain Interrupt handlers.
Ans:
Interrupts means the processor is transferred temporarily to another program or function. When that program is completed, the processor will be given back to that program to complete the task.
Interrupt handler is the function that the kernel runs for a specific interrupt. It is also called Interrupt Service Routine. Interrupts handlers are the function that matches a particular prototype and enables the kernel to pass the handler information accurately.
145. What is page frame?
Ans:
A page frame is a block of RAM that is used for virtual memory. It has its page frame number. The size of a page frame may vary from system to system, and it is in the power of 2 in bytes. Also, it is the smallest length block of memory in which an operating system maps memory pages.
146. What is the difference between “rm” and “rm –r”?
Ans:
“rm” command is used to delete all the files while “rm –r” command is used to delete all the files in a directory and also in subdirectories.
For Example,
rm file.txt: It will delete the file with name file.txt
rm –r directory: It will remove directories and subdirectories and also their contents.
147. Explain the command and method to change the file permissions in Linux.
Ans:
chmod command is used to change the permissions of a file. There are three parts to consider to set the file permissions.
User (or Owner)
Group
Other
3 types of file permission that is given to a file.
r – Reading permission
w – Writing permission
x – Execution permission
For example, chmod 751 filename
Then, three number 751 describes permissions given to the user, group and other in the order. Each number is the sum of the values,i.e. 4 for reading, 2 for write, 1 for execute.
Here 751 is the combination of (4+2+1), (4+0+1), (0+0+1).
So, chmod 751 filename will provide read, write and execute permission to the owner; read and execute permission to the group and only execute permission to the others.
148. How can we edit a file without opening in Linux?
Ans:
sed command is used to edit a file without opening. sed is the acronym for StreamEditor. The “sed” command is used to modify or change the contents of a file
For example, we have a text file with below content
>cat file.txt
We want to replace the content of the file and we want to replace “sed” with “vi”. So, we will use below command for this.
>sed ‘s/sed/vi/’ file.txt
vi command is used to edit a file.
So, sed is replaced with vi in the text.
149. Explain grep command and its use.
Ans:
grep command in Linux is used to search a specific pattern. Grep command will help you to explore the string in a file or multiple files.
The syntax for grep command:
grep ‘word’ filename
grep ‘word’ file1 file2 file3
command|grep‘string’
For example,
grep “smith” passwd
grep “smith” passwd shadow
netstat -an | grep8083
cat /etc/passwd | grep smith
150. Explain file content commands along with the description.
Ans:
There are many commands present in Linux which are used to look at the contents of the file.
head: to check the starting of a file.
tail: to check the ending of the file. It is the reverse of head command.
cat: used to view, create, concatenate the files.
rrep: used to find the specific pattern or string in a file.
more: used to display the text in the terminal window in pager form.
less: used to view the text in the backward direction and also provides single line movement.
The demand for Linux is increasing day by day and it opens many doors of jobs for you. The set of above mentioned 30 Linux interview questions and answers would act as a last minute interview preparation guide for you. These questions are useful for the fresher as well as the experienced candidates. So, no need to worry about cracking the Linux interview. Just prepare well for the questions that will be helpful for you.
151. What is the difference between CTRL-C and CTRL-Z?
Ans:
When you have a process in progress which handle your prompt, there are some signals (orders) that we can send to theses process to indicate what we need:
Control+C sends SIGINT which will interrupt the application. Usually causing it to abort, but a process is able to intercept this signal and do whatever it likes: for instance, from your Bash prompt, try hitting Ctrl-C. In Bash, it just cancels whatever you’ve typed and gives you a blank prompt (as opposed to quitting Bash)
Control+Z sends SIGTSTP to a foreground application, effectively putting it in the background on suspended mode. This is very useful when you want the application to continue its process while you are doing another job in the current shell. When you finish the job, you can go back into the application by running fg(or %x where x is the job number as shown in jobs).
152. I want to troubleshoot my network but I don’t know how does the traceroute command work exactly?
Ans:
Traceroute is a program that shows you the route taken by packets through a network. It traces the route of packets from source to destination. It is commonly used when your network doesn’t work as well and you want to examine where can be the problem. Traceroute sends a UDP packet to the destination taking advantage of ICMP’s messages. ICMP has two types of messages: error-reporting messages and query messages. Query messages are generally used to diagnose network problems (the ping tool uses ICMP’s query messages). The error-reporting messages as the name suggest report errors if any in the IP packet; it uses Destination unreachableand Time exceeded errors message. It works by theses steps:
Traceroute creates a UDP packet from the source to destination with a TTL(Time-to-live) = 1
The UDP packet reaches the first router where the router decrements the value of TTL by 1, thus making our UDP packet’s TTL = 0 and hence the packet gets dropped.
Noticing that the packet got dropped, it sends an ICMP message (Time exceeded)back to the source.
Traceroute makes a note of the router’s address and the time taken for the round-trip.
It sends two more packets in the same way to get an average value of the round-trip time. Usually, the first round-trip takes longer than the other two due to the delay in ARP finding the physical address, the address stays in the ARP cache during the second and the third time and hence the process speeds up.
The steps that have occurred up til now, occur again and again until the destination has been reached. The only change that happens is that the TTL is incremented by 1 when the UDP packet is to be sent to next router/host.
Once the destination is reached, Time exceeded ICMP message is NOT sent back this time because the destination has already been reached.
But, the UDP packet used by Traceroute specifies the destination port number to be one that is not usually used for UDP. Hence, when the destination computer verifies the headers of the UDP packet, the packet gets dropped due to the improper port being used and an ICMP message (this time – Destination Unreachable) is sent back to the source.
When Traceroute encounters this message, it understands that the destination has been reached. Even the destination is reached 3 times to get the average of the round-trip time.
153. NSCD sometimes die itself and DNS resolving doesn’t happen properly. How can we avoid NSCD for DNS and there is a disadvantage to bypass it?
Ans:
nscd is a daemon that provides a cache for the most common name service requests. When resolving a user, group, host, service…, the process will first try to connect to the nscd socket (something like /var/run/nscd/socket).
If nscd has died, the connect will fail, and so nscd won’t be used and that should not be a problem.
If it’s in a hung state, then the connect may hang or succeed. If it succeeds the client will send its request (give IP address for www.google.com, passwd entries…). Now, you can configure nscd to disable caching for any type of database (for instance by having enable-cache hosts no in /etc/nscd.conf for the hosts database).
However, if nscd is in a hung state, it may not be able to even give that simple won’t do answer, so that won’t necessarily help. nscd is a caching daemon, it’s meant to improve performance. Disabling it would potentially make those lookups slower. However, that’s only true for some kind of databases. For instance, if user/service/group databases are only in small files (/etc/passwd, /etc/group, /etc/services), then using nscd for those will probably bring little benefit if any. nscd will be useful for the hosts database.
About the author
Leave a Reply Cancel reply
This site uses Akismet to reduce spam. Learn how your comment data is processed.