Linux Interview Questions and Answers

Q1. What is Linux?

Ans. Linux is an Open-Source Operating System first introduced by Linus Torvalds.  It is based on UNIX and it is available freely. It can be executed on different hardware platforms such as Intel, HP, MIPS, Motorola, SPARC, IBM etc. 

Q2. What are the main components of LINUX?

Ans. Major components in the Linux operating system are:

  • Kernel: It is the primary component that manages hardware and basic operations in the Linux operating system.
  • Shell: It is an interpreter that executes commands for different functions in Linux.
  • GUI: Graphical User Interface (GUI) is an interface through which users interact with the system. It comprises images, text boxes, buttons, checkboxes etc.
  • System Utilities: It includes software functions that help the user to manage the basic functioning of a computer.
  • Application Programs: These are a set of software programs intended to complete certain tasks

Q3. How to check and verify the status of the bond interface?

 

Ans. Using the command ‘cat /proc/net/bonding/bond0,’ we can check what mode is enabled and what LAN cards are used in this bond. In this example, we have one one bond interface. However, we can have multiple bond interfaces like bond1, bond2 and so on.

Q4. What do you understand by Linux Kernal? Is it legal to edit it?

Ans. Kernal essentially refers to that core component of the PC working framework that gives fundamental administrations to alternate parts and in addition connects with client summons. With regards to 'Linux Kernal, it is referred to as low-level system software providing an interface for user-level interactions.

Linux Kernal is considered as free and open-source programming which is fit for managing hardware resources for the clients. As it is released under General Public License (GPL), it winds up legal for anybody to alter it.

Q5. How can we use LINUX?

Ans. LINUX is used widely because it is completely different from other operating systems with something extra i.e. some additional features

  • It is an open-source operating system where programmers get the advantage of designing their own custom OS.
  • Software and the server licensing required to install Linux is completely free and can be installed on many computers as required.
  • It has low or minimum but controllable issues with viruses, malware, etc
  • It is highly secured and supports multiple file systems.

Q6. Define GUI?

Ans. GUI stands for the Graphical user interface. GUI is considered as the most attractive and user-friendly because it consists of the usage of images and icons.

Q7. Define CLI?

Ans. CLI stands for Command Line Interface. It is a way for humans to interact with computers and is also known as Command-line user interface.

Aspired to become a Linux? Explore the post to discover the know-how on Linux Training.

Q8. What is the maximum length for any file name under LINUX?

Ans. The maximum length for any filename under Linux is 255 characters.

Q9. How to Enable ACLs for /home partition?

Ans. Add following entry in /etc/fstab LABEL=/home /home ext3 acl 1 2 Now remount /home partition with acl option. mount -t ext3 -o acl /dev/sda3 /home

Q10.  How do you create ext4 file system?

Ans. # mke2fs -t ext4 /dev/DEV

Q11. What is the name and path of the main system log?

Ans. By default, the main system log is ‘/var/log/messages’. This file contains all the messages and the script written by the user. By default, all scripts are saved in this file. This is the standard system log file, which contains messages from all system software, non-kernel boot issues, and messages that go to ‘dmesg’. dmesg is a system file that is written upon system boot.

Q13. What is partial backup?

Ans. When you select only a portion of your file hierarchy or a single partition to back up, it is called partial backup.

Q14. Differentiate between LINUX and UNIX?

Ans.

LINUXUNIX
LINUX is an open-source free operating system used in the functioning of computer hardware & software, system application, game development etc.UNIX is also an operating system mostly used in internet servers, HP, intel etc.
LINUX is available in both the versions- freely downloaded and distributed as well as priced minimally.UNIX comes in different versions with different price structures.
Linux can be easily used by anyone such as web developers, software engineers, home users, etc.UNIX is developed to be generally used for servers, mainframes, and workstations.
The file support system in LINUX comprises Ext2 to Ext4, Xfs, Jfs, FAT, Btrfs, etc.The file support system in UNIX consists of gpfs, jfs hfs, etc.
In LINUX, BASH (Bourne Again Shell) serves as the Linux default shell i.e. text-mode interface that can be executed on multiple command-line interpreters.Bourne shell acts as the text mode interface that is compatible with multiple other interfaces including BASH.
LINUX comprises two GUIs, Gnome and KDE.In UNIX, the Common desktop environment serves as a GUI.
Examples: Fedora, Red Hat, Debian, Ubuntu etc.Examples: Linux, Solaris

Q15. What are LINUX basic commands?

Ans. In Linux, commands are case-sensitive and more often than not they are entirely in lowercase. Items that are surrounded by brackets ([]) are optional. You will more than likely use at least some of these commands every time you log into a Linux system. Become familiar with these commands because they can get you pretty far in a short amount of time.

  • ls - Lists directory contents. You will use ls to display information about files and directories.
  • cd [dir] - Changes the current directory to dir. If you execute cd without specifying a directory, cd changes the current directory to your home directory. This is how you navigate around the system.
  • pwd - Displays the present working directory name. If you don't know what directory you are in, pwd will tell you.
  • cat [file] - Concatenates and displays files. This is the command you run to view the contents of a file.
  • echo [argument] - Displays arguments to the screen.
  • man command - Displays the online manual for command. Type q to quit viewing the manual page. The documentation provided by the man command is commonly called "man pages." exit, logout,
  • or Ctrl-d - Exits the shell or your current session.
  • clear - Clears the screen

Q16. Define Automatic processes?

Ans. Automatic or batch processes are not connected to a terminal. Rather, these are tasks that can be queued into a spooler area, where they wait to be executed on a FIFO (first-in, first-out) basis. Such tasks can be executed using one of two criteria:

At a certain date and time: done using the at command.

At times when the total system load is low enough to accept extra jobs: done using the batch command. By default, tasks are put in a queue where they wait to be executed until the system load is lower than 0.8. In large environments, the system administrator may prefer batch processing when large amounts of data have to be processed or when tasks demanding a lot of system resources have to be executed on an already loaded system. Batch processing is also used for optimizing system performance.

Q17. Explain Linux Kernel? Is it possible and legal to edit Linux Kernel?

Ans. The low-level system software is referred to as the Linux kernel. It is mainly used to allocate resources and to provide a medium for the user interface.

Yes, it is possible as well as legal to edit Linux Kernel. Since Linux comes under the General Public License (General Public License), it can be edited and modified by the end-users. 

Q18. What is BASH?

Ans. BASH refers to Bourne Again SHell. It is a replacement of the initial Bourne shell represented by/bin/sh. And it is created by Steve Bourne. It is the better version of the previous and original bourne shell as it contains unique additional features that are easy to use. Later it got adopted as a default shell script for most of the systems operating Linux.

Q19. What is LILO?

Ans. LILO is a term given to LInux LOader. It loads the Linux Operating System into the system’s main memory for execution. Mostly all the computers come with inbuilt boot loaders in some of the versions of Mac OS or windows. For using Linux OS, a special boot loader needs to be installed in the system and one such boot loader is LILO. One of the major advantages of using this boot loader is that it can boot Linux OS really fast. 

Q20. Which are the common Shells that are used in Linux?

Ans. Some of the common Shells that are used in Linux are

  • BASH: Bourne Again Shell-  default shell for almost all the Linux operating systems
  • KSH: Korn Shell- high-level programming language shell
  • CSH: C Shell- shell with C like syntax that offers job control and spell check and correction functions
  • ZSH: Z Shell- It offers unique features like filename generation, login/logout functions, startup files, closing comments etc.
  • FISH: Friendly Interactive Shell- It offers unique such as web-based configuration, scripting and auto-suggestions.

Q21. Define is a swap space?

Ans. It is a space that temporarily stores concurrent executing programs in Linux. When RAM has a shortage of enough space to store the programs that are executing in a system, then swap space comes in action.

Q22. What are the advantages of using LINUX?

Ans. There are many reasons why LINUX is preferred over other operating systems. Some of them are listed below.

  • Being an open-source operating system, it provides the opportunity for the programmers to customize their own operating system
  • Software programs and server licences that are needed to install Linux are available for free and can be installed on multiple systems.
  • It is comparatively more secure than other operating systems etc.
  • It is highly robust and scalable as it is compatible with most of the hardware and software programs and supports many file systems.

Q23. What is the Root account in Linux?

Ans. It is the primary account similar to a system administrator that controls all the functioning in the system. It is a default account that gets loaded whenever the Linux is set up. Some of the functions performed by root account are:

  • user accounts creation
  • user accounts maintenance
  • Allocating permissions for the new accounts created.

Q24. What are the advantages of using an open-source operating system?

Ans. In open-source, software including the source code is distributed without any cost to the end-users. People can customize the source code to customize and add features of their choice. They can even debug the source code if any error creeps in. The whole community can be benefited with enhanced features as the people can again distribute it freely after customizing it.

Q25. Differentiate BASH and DOS?

Ans. 

Sl. no.BASHBASH
1.Commands used for different functions are case-sensitive.Commands used for different functions are not case-sensitive.
2.(‘/’ forward slash) in BASH is used to separate directories. (” backslash) is used as an escape character.(‘/’ forward slash) in DOS is used as a command argument delimiter. (” backslash) is used as a directory separator.
3.A naming convention is followed in which 8 characters are fixed for file name postfixed with 3 characters for the extension.A naming convention is not followed

Q26. What is the importance of the GNU project?

Ans. GNU being a free software movement provides several advantages as it gives the flexibility to modify the programs according to their use and convenience. It is also allowed to redistribute the modified copies of software for free and release it for the public to use it.

Q27. How can a command prompt be opened while writing a command?

Ans. Command prompt is found in the default shell and to open it Ctrl-Alt-F1 is pressed. This will start the command line interface (CLI) from which commands can be entered and executed.

Q28. What is the preferred size of a swap partition in Linux?

Ans. Generally, the size of the swap partition is twice the size of physical memory present in the system. If it is not possible to have this size, then the minimum required size for a swap partition is the amount of memory present in the system

Q29. Define Virtual Desktop?

Ans. This is a special feature which is very useful for the users who enhance the physical boundaries of a screen to a larger extent. With a virtual desktop, a virtual screen is created that can expand the normal screen of the system. A virtual desktop can be implemented by using 2 ways

Switching Desktops

With switching desktops, distinct virtual desktops can be created to run programs. Each virtual desktop acts as a separate desktop and programs executing on these desktops can only be accessed by the users who are using that particular virtual desktop 

Oversized Desktops

It does not provide distant desktops but lets the user scroll over a desktop that is expanded and is larger in size than the desktop having a normal physical screen. 

Q30. What are symbolic links in Linux?

Ans. Symbolic links are the same as shortcuts in Windows and they point to files or directories and programs. It provides instant access to the desired directories or files without going to the full pathname.

Q31. Explain daemons in Linux?

Ans. Daemons are those computer programs that run as a background process to execute those functions that are not there in the base Operating System. They are used to run the services in the background so that they can not be directly controlled by the end-users. They are also used to handle periodic requests so that these requests can be sent to the appropriate programs for implementation. 

Q32. What are the commands to change permissions in Linux?

Ans. Only system administrators or file owners can grant or change the access permissions in Linux. Permissions are granted using the chmod command. + symbol is used to add permission and – symbol is used to deny permission, followed by any of these letters: u (user), o (others), g (group), a (all), r (read), w (write) and x (execute). For instance, the command chmod u+rw FILE23.TXT is used to grant read and write access to the file FILE23.TXT, which is assigned to users.

Q33. Write down the process states in Linux?

Ans. The process states in Linux are:

  • Ready: The process is ready for execution
  • Running: The process is in the execution state
  • Blocked or wait: Process is waiting for input or is blocked for execution from the user
  • Terminated or Completed: Process is successfully completed or was terminated due to some error by the Operating System
  • Zombie: Process is terminated by the system, but the information is still there in the process table.

Q34. What are the ways to access partitions under Linux?

Ans. In Linux, numbers are assigned as a suffix to the drive identifier. For instance, the first IDE hard drive had three primary partitions, will be written as name/number just like /dev/hda1, /dev/hda2 and /dev/hda3.

Q35. What is the use of grep command in Linux?

Ans. Grep is the term used for Global Regular Expression Print. It is used to search for a text expression in a file by matching the patterns based on a regular expression.

It follows the following syntax

Syntax: grep [text options] pattern [filename]

For Example:

$ grep -c "shell script" inlinux.txt

This command will print the count of the word “shell script” in the “inlinux.txt” file.

Q36. What does hard links refer to in Linux?

Ans. Hard links are the links that point directly to the file and not to the pathname. It means even if the file is renamed or moved from one location to the other, the link will remain the same as the link is for the file and not for the path where the file is located.

Q37. What is Process Management System Calls in Linux?

Ans. Process management system calls are:

  • fork () – It is used for the creation of new process
  • exec(): It is used for the execution of a new program
  • wait(): It is used to direct the system to wait until the process execution is finished
  • exit(): It is used to exit from the current process
  • System Calls that are used to get Process ID are:
  • getpid():- It is used to get the unique process id (pid) of the process
  • getppid():- It is used to get the unique id of the parent process

Q38. What is the role of ‘ls’ command in Linux?

Ans. The ls command lists down all the files in a particular directory. The syntax for using this command is:

$ ls  

For instance: The command to list all the files in the tutorial directory will be as follows:

$ ls tutorial/

Different options can be used with ls command to provide extra information about the file/folder from where information needs to be fetched. The options are:

  •  -l  Lists long format(displays the access permissions of the file)
  • -a  lists all the files including hidden files
  •  -i  lists all the files along with their inode number
  • -s  lists all the files along with their size
  • -S  Lists all files with their respective size and sorts the list by the size of a file
  • -t   sorts all the listed files by their date and time

Q39. What are filenames that are preceded by a dot?

Ans. Generally, all the hidden files are preceded by a dot. These files hold important or setup info as they can be configuration files. Keeping these files as hidden makes them secure from being accidentally deleted.

Q40. What is the use of redirection operator in Linux?

Ans. The redirection operator is used when there is a need to use the output of one command as an input to the other command or file. It is generally used in 2 ways

‘>’ – this operator overwrites the existing data in the file or makes a new file.

‘>>’ appends the new data at the end of the file or makes a new file. 

So in simple words, in this ‘>’ redirection operator, the data in the file is overwritten and in this ‘>>’ redirection operator, the data is appended.

Q41. Is it possible to execute more than 1 command from a single command line entry? If yes, how?

Ans. Yes, it is possible to execute several commands from a single command line entry by separating them using a semicolon symbol. For instance: Consider the example below in which a series of commands are issued from a single entry.

ls –l cd .. ls –a EXAMPLE of having 3 commands from the single line: ls -l cd.. ls -a EXAMPLE

Q42. What is the use of tar command in Linux?

Ans. An archived file can be created or extracted by using tar command in Linux. For instance: to extract all the files from the archive ‘example.tar.gz’, the following command will be used:

$ tar -xvzf example.tar.gz

To create an archive of all the file stored in /home/linux/, following command can be used:

$ tar -xvzf filename.tar.gz

where c refers to create archive, x refers to extract, v refers to verbose and f refers to file

Q43. How programs can be shared across different virtual desktops in Linux?

Ans. For sharing the programs across different virtual desktops, press the button in the upper left-hand corner of a window which appears to be a pushpin. It will "pin" that application thus making it visible at the same position on the physical screen in all virtual desktops.

Q44. What does Latch mean in Linux?

Ans. A Latch is a binary storage device that stores the file temporarily and is controlled by a timing signal with the value being either 0 or 1. It has two stable states. The high output state denotes 1 and low output state denotes 0. If the power is on, it can store 1 bit of data. 

Q45. What does a nameless or empty directory signify in Linux?

Ans. In Linux, an empty directory acts as the nameless base of the file system. It serves as an attachment for all other files, directories, devices and drives.

Q46. What is a Microprocessor?

Ans. It is a single-chip device that is used to execute commands. It fetches, decodes and then decodes the instructions from the memory. The basic functions carried out by microprocessor are:

basic mathematical operations such as add, subtract, multiply, and divide

moving data from one place to another

decision making based on the conditions and then moving on to new instructions based on those decisions. 

Q47. What does the pwd command do?

Ans. The pwd command refers to the print working directory. It displays the pathname of the directory which is currently in use.

For instance: If we will write the below command

Pwd

The following output will be generated:

/home/ajay12/myDir 

Q48. Explain Regular Expressions in Linux

Ans. Regular Expressions in Linux are used to search for options with specified patterns. Some commands used with regular expressions are sed, tr,vi and grep.

Some symbols used with Regular Expressions are:

.To match any character
$To match the end of the String 
^To match the beginning of the String
 It is used to depict special characters
*To match zero or more than one characters
? It is used to match exactly one character

 

Q49. How switching from one desktop environment to another can be done such as KDE to Gnome?

Ans. Considering that these two desktop environments are already installed, just log out from the current session through the user interface. Then again login from the login screen by entering the ID and password and choose the session type you wish to continue with. This will remain the default desktop environment until you change it to some other environment.

Q50. What is the effect of case sensitivity while using the commands?

Ans. Linux being a case sensitive language, it can alter the output if every character is not encoded as it is including the uppercase and lowercase letters. For instance- CD, cd, and Cd will produce different outputs as these are three different commands. If a command is written in lowercase where it should be in uppercase, it will generate different results.

Q51. How many disk partitions are required to install Linux?

Ans. Minimum 2 partitions are required to install Linux. In one partition, all the local files are stored including configuration files of the OS, application files and services along with user files. The second partition is used as Swap Space which is an extended memory for RAM in Linux. 

Que52. Define environmental variables?

Ans. Environmental variables are also known as global shell variables. They are global settings responsible for controlling the shell’s function along with other Linux programs.

Q53. How shortcuts can be created for long path names?

Ans. Shortcuts can be created by using a feature called filename expansion in which TAB key is used for this purpose. The condition is that the pathname should be unique and the shell which is in use should support this feature. For instance, path name /home/shell/example directory, will be written as follows: /ho[tab]/she[tab]/exa[tab].

Q54. List down the modes that are used while using vi editor?

Ans. Vi editor uses 3 modes for its functioning

Command mode – This is the mode from where the commands are initiated

Edit mode – This is the mode from where text editing is done

Ex mode – This is the mode where instructions are given to interact with Vi to process a file.

Q55. What does the Ctrl+Alt+Del key combination do in Linux?

Ans. It works similarly as in windows to restart a system. The only difference is that the reboot starts immediately in Linux after striking this key combination without giving any notification or confirmation message.

Q56. What does /usr/local directory stores?

Ans. This directory holds locally installed files and is mainly used in the environments where files are generally stored in a network. They are used for those software packages that are installed from the source or software that are not official to use. Local files normally go to /usr/local/bin, /usr/local/lib etc. kinds of directories in Linux.

Q57. List down some of the Linux distributors with its usage?

Ans.  Linux distributors are often called Distros. Different parts of LINUX such as the kernel, graphical programs, system environment etc. are developed and distributed by different organizations. Distros assemble these parts and compile them in an operating system that is ready to be installed in a system for use. There are more than six hundred Linux distributors in the market but some of the well-known distributors are

  • UBuntu: It is the most common Linux Distribution that comes with many pre-installed apps and repositories in its library. It is extremely user-friendly, easy to use and works similar to a MAC operating system.
  • Debian: It is the fast, stable and user-friendly Linux Distribution.
  • Linux Mint: It is mostly used by those who are not used to Linux as it works on windows.
  • Fedora: It provides the latest version of Linux but is less stable as compared to other distributions. By default, it has the GNOME3 desktop environment.
  • Arch Linux: This is not suggested for beginners as every package needs to be installed by the users according to their requirements.
  • Red Hat Enterprise: It is a stable and durable distribution from Linux that is mostly used for commercial purposes and therefore needs to be tested rigorously before releasing it.

Q58. How comments can be inserted in the command line prompt?

Ans. Comments are always followed by # symbol in Linux. From this symbol, shell understands that this is a comment and not a command. Shell completely ignores the content which is followed by # symbol. For instance "# Comment is followed by this symbol and not the command."

Q59. How memory usage can be tracked in LINUX?

Ans. It is important to determine the total memory used by different programs in Linux in order to analyse whether the resources and the server is being used adequately by the users or not. Below are some of the methods to find out the memory in use. 

Free command: Memory usage can be checked by this simple command. For instance, ‘$ free –m’, in this command ‘m’displays all the data in MBs.

Vmstat: With this command, the memory usage statistics can be known. For instance, ‘$ vmstat –s’

/proc/meminfo: Memory in use can also be known by reading the file /proc/meminfo file. For instance,  ‘$ cat /proc/meminfo’

Top command: Total memory which is in use along with the RAM usage can be determined by using this command.

Htop: Memory usage along with other useful details can be displayed by using this command.

Q60. How can an ongoing process be terminated?

Ans. Every process has a unique id known as pid in Linux. Kill command followed by pid is used to terminate a process. To terminate all the processes in one go, kill 0 is followed by pid.

Q61. How does command grouping work in Linux?

Ans. Parentheses can be used to group commands in Linux. For instance, To send the recent date and time along with a file named EXAMPLE to a second file named GROUPING, command grouping can be applied by using this command (date cat EXAMPLE) >GROUPING