Linux Interview Questions - BRS MEDIA TECHNOLOGIES
Linux-Interview-Questions

Linux Interview Questions

S. NoNotes
1What is Linux?
Linux is an open-source operating system inspired by UNIX.
It was first introduced by Linus Torvalds.
Linux is just a Kernel and a Linux distribution makes it a usable operating systems.
It’s the preferred OS for computers, servers, mainframes, mobile devices and embedded devices.
2How different is LINUX when compared the UNIX?
Unix is a propriety operating system from Bell Laboratories. The Open Group holds the UNIX trademark & manage the UNIX trademark licensing program. Companies have their own licensad UNIX:IBM(AIX), Solaris (Sun OS), HP(HP-UX), Apple(OSX).
Linux is free, open source and intended as a non-propriety operating system for the masses. Linux is a clone of Unix, written from scratch by Linux Torvalds & his team. Linux distro-> GUI system + GNU utilities.
3What is the importance of the GNU project?
–GNU project is a result of the Free Software Movement started by Richard Stallman
–It supported the open-source & collaborated development of operating system software.
Acronym of GNU is “GNU’s Not Unix!”
GNU project was intended to create a UNIX-like OS; but free & open-source.
This lead to the birth of Linux OS-> Linux Kernel + GNU utilities
4What is Linux Kernel?
–The Linux Kernel is a low-level systems software whose main role is to manage hardware resources for the user.
–It is the core of any OS & it is responsible for translating the user commands into equivalent language understood by the computer hardware.
5What is Shell?
What is BASH?
Shell
–The Shell is a program that takes commands from the keyboard and passes them to the operating system(kernel) for performing.
–During the initial days, Shell was the only mode for communicating with kernel(via the CLI)
BASH
–BASH is short for Bourne Again SHell. Its a replacement to the original Shell (/bin/sh).
–BASH combines the features of the original Shell+additional functionality to make it easier and more dconvenient to use.
— Nowadays, BASH has been adopted as the default shell for most Linux systems.
(BASH – Born Again Shell named after person Stephen Richard “Steve” Bourne )
Stephen Richard “Steve” Bourne (born 7 January 1944) is an English computer scientist based in the United States for most of his career. He is well known as the author of the Bourne shell ( sh ), which is the foundation for the standard command-line interfaces to Unix.
6How many types of shells are there in Linux?
A shell is a program that acts as an interface between the user and the operating system (OS) kernel. The first shell that came to the world was the Thompson shell which was written by ken Thompson at AT&T Bell Labs. What we got was the Bourne shell which was developed by Stephen Bourne at Bell Labs. The Thompson shell was not a scripting shell and it was replaced by Bourne shell as which was accompanied by many improvements.
Types of Shells in Linux
— The Bourne Shell
— Bash Shell
— The C Shell
— TENEX c shell
— The Korn Shell
— The Z Shell
— Fish Shell
Command to view All shells in Linux: $ cat /etc/shells
Output of above command:
# /etc/shells: valid login shells
/bin/sh
/bin/bash
/bin/rbash
/bin/dash
7What are Daemons?
— A daemon is a type of program that runs in the background, free of user control.
— They can be activated (initiated as a process) by the occurrence of a specific event or condition.
— Daemons accommodate service requests from other programs or hardware activity or requests from other computers on a network.
— After the request is serviced, the Daemon disconnects and waits for further requests.
8What is LILO?
— LILO is an acronym for Linux Loader.
— It is a boot loader, which loads the Linux operating system into main memory so that it can begin its operations.
— LILO can be configured to boot other operating systems also.
— LILO is costomizable, which means that if the default configuration is not correct, it can be changed. Conig file for LILO is lilo.conf.
Note:- This is not used now days the default is GRUB- GRand Unified Bootloader.
9What are the advantages of Linux being open-source?
— Being open-source, Linux gives users access to the source code.
— Open source allows users to distribute the software, including source the code (freely) to anyone interested
— It allows users to add features, debug and correct errors in the original source code.
— When the source code has been improved, it can be freely redistributed (open-source collaboration).
— This benefits everyone in the open-source community.
10What are the basic components of Linux OS?
— Kernel
—- Kernel is the core of Linux OS which is responsible for all the major activities.
—- It interacts directly with the underlying hardware while also providing the required abstraction to hide low level hardware details to the system or application programs.

— Shells & GUI (System Libraries)
—- They are special functions or programs using which application programs or system utilities access Kernel’s features.
—- These libraries implement most of the funtionalities of the OS & do not require Kernel module’s code access rights.

— System Utilities
—- System utility programs are responsible for the execution of special and individual tasks.
11How to check Memory stats and CPU stats as a Linux admin?
— By using ‘free’ & ‘vmstat’ command, you can see the physical memory & virtual memory statistics respectively.
— By using the ‘sar command, you can see the CPU utilisation & other stats.
12How to reduce or shrink the size of LVM partition?
The actions need to be performed in the below order:
1. Unmount the filesystem using unmount command
Syntax: umount /dev/hda2/dir1
2. Use resize2fs command
Syntax: resize32fs /drv/mapper/myvg-mylv 10G
3. Nou use lvreduce command
Syntax: lvreduce -L 1G /dev/mapper/myvg-mylv
The above Command will shrink the size LVM partition and fixes the filesystem size to 10GB.
13Explain the functionality of root user.
–The root user is similar to a superuser or a system administrator.
— Root user (superuser) has ultimate control and access to all files / directories in the system. Example: Creating and maintaining user accounts, assigning different permissions for each account, etc.
— Another advantage: restricted programs can be executed from the terminal by using the root account
— Root is the default account every time Linux is installed.
13What is CLI?
What is GUI?
— CLI stands for Command Line interface. This interface allows user to type declarative commands to instruct the computer to perform operations.
— Linux CLI is called Terminal and the commands will be interpreted by the Shell. Preferred by developers / programmers.
— Advantage: Multiple steps can be executed by specifying a single command.

— GUI stands for Graphical User interface and makes the system attractive
— Users who find it difficult to remember commands, can use the GUI.
— GUI allows the users to navigate/ access files by clicking on images and icons.
14What is Swap space?
What is the typical size for a Swap partition under Linux system?
Swap space is a certain amount of space used by Linux to temporarily hold active programs. This happens when RAM does not have enough memory to hold all programs that are being executed. Swap space is defined in File System.
— 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.
15How do you access partitions under Linux?
— Linux assigns numbers at the end of the drive to identify them uniquely.
— For example, if the first IDE hard drive had three primary partitions, they would be: /dev/hda1, /dev/hda2 and /dev/hda3.
— For example, if the first SCSI hard drive had three primary partitions, they would be: /dev/sda1, /dev/sda2 and /dev/sda3.
16How are hard drives and floppy drives referred in Linux files system?
— Floppy drives can be accessed by using: /dev/fd0 and /dev/fd1
— IDE/EIDE hard drives can be accessed by using: /dev/hda, /dev/hdb, /drv/hdc and so on.
— SATA/SCSI hard drives can be accessed by using: /dev/sda, /dev/sdb, /drv/sdc and so on.
17In Linux, how are names assigned to the different serial ports?
— Serial ports are identified as /dev/ttyS0 to /dev/ttyS7.
Command for Terminal: ls -l /dev/ttyS*
— These are the equivalent names of COM1 to COM8 in Windows.
18How are parallel ports (like printers) referenced in Linux?
— Printer ports are identified as /dev/lp0, /dev/lp1 and so on.
Command for Terminal: ls -l /dev/lp*
19What are the kind of permissions available in Linux?
— There are basically 3 levels of file/ directory permissions in Linux:
Read: Users only read the files or list the directory contents.
Write: Users can write information to the file and create files/sub-directories in a directory.
Execute: Users can run the file or lookup a specific file within a directory.
— Besides these, you can have a combination of all these three levels of permissions or two of them or only one of them.
20How do you can change permissions under Linux?
The following commands are used along with operators as arguments:-
— chmod : To change the permissions of files and directories
— chown : To change the owner of files and directories
— chgrp : To change the group ownership of file and directories
Example:
— chmod g+wx, o-wx, u=rwx filename
— chown username filename
Denotions
Users – ‘u’ , Groups -‘g’ , Others – ‘o’ , All – ‘a’
Operators
Add permissions: ‘+’
Revoke permissions: ‘-‘
Replace permissions: ‘=’
21What are Symbolic links?
— Symbolic links are similar to shortcuts in Windows. Also called soft links.
— Symbolic links can point to either programs or files or directories; but do not contain the data in the target file.
— Benefit: Allows instant access to a file without having to navigate to the entire pathname.
Command:
Create command: ln -s /complete_path /symbole_name
Output command: ls -l /symbolname
Output screen:
File permissions 1 Group User DateTime /symbole_name -> /complete_path
lrwwxrwxrwx 1 root root 43 May 28 19:08 /symbole_name -> /complete_path
22What are the qualities of soft links?
— Soft links files have different inode numbers compared to the source file.
— The soft link file will be of no use if original file is deleted.
— Soft links are not updated.
— They can create links between directories.
— They can cross file system boundaries.
23What are are Hard links?
— Hard links point directly to the physical file on disk, and not to the path name.
— Even if you rename or move the original file, this link will not break.
— Since this link points to the file itself and not the path where the file is located.
24What does a nameless(empty) directory represent?
— An empty directory name serves as a nameless base for the Linux file system.
— This serves as an attachement for all other directories, files, drives and devices.
25How can you create folders and files using the Terminal?
— To create a folder the command used is : mkdir
— To create a file any of the following commands can be used:
—- vi
—- vim
—- gedit
—- nano and many more
26What are the different ways to view the contents of a file?
To view file contents, you can use any of Linux’s in built editor or a graphical editor. Some of them are:
— cat
— vi
— vim
— gedit
— kate / kwrite
— pico
— nano and many more.
27What are Environmental variables?
— Environmental variables are global settings that control the behaviour of Shells, software packages installed in Linux and other processes.
— The path were the various software’s are installed, will be stored as environment variables.
— Environmental variables are thus used to pass information into processes that are spawned from shell.
Command: env
28What is the functionality of ‘tab’ key in CLI?
— ‘Tab’ key is a shortcut key whic is used to autofill the complete filename/ pathname of any file or directory.
— For example, while navigating to directory, the next directory in the path is shortlisted.
To reach /home/user/Docements/Folder1/File1.txt,
You can press ‘Tab’ after typing in a few characters like:
/ho[tab]/us[tab]/Docu[tab]/Fo[tab]/Fi[tab]
29What is Redirection in Linux?
— In Linux, Redirection is used to pass the output of one operation as input to another operation in the same command.
— The operator used for Redirection is ‘>’
Example:-
cat file1 file2 >file3.txt
cat >> file1.txt
30What is GREP command?
— To search for a particular string/word in a text file ‘grep’ command is used.
— It also supports pattern-based searching.
— Pattern-based searching is done by including options and parameters in the command.
31How to terminate an ongoing process in Linux?
— Every process in the Linux system is identified by a unique process id or ‘pid’.
— To terminate any process, use the ‘kill’ command followed by its pid.
— To terminate all process at once, use kill 0. (not recommended in production environment)
— You can also terminate an ongoing process by pressing ‘ctrl+z’.
32How to insert comments in command prompt?
— Comments are inserted by using the ‘#’ symbol before the comment text.
— When ‘#’ is prefixed to any line, then that line is ignored and will not be executed by the Shell.
33Can you insert several commands in a single command line entry? if so, then how?
— Several commands can be combined by separating each of them by using a semicolon (;).
— For example, you can issue such series of commands in a single entry.
Command : mkdir dir1 ; cd dir1 ; touch j k l this is called command chain
34Write a command that will display all the ‘.txt’ files, along with its permissions.
$ ls -a -l *.txt
— ls command will list down all the content in the directory.
— -a is used to include even hidden files.
— -l is used to display the contents in long format.
— *.txt filters the results and displays only .txt files.
35Write a command that will look for files with ‘txt extension, and has the occurrence of the string “abc” in it.
Command $ find / -name *.txt | xargs grep -i abc
36How to find the status of a process?
Command $ ps aux
37What is command to calculate the size of a folder?
Comand $ du -sh /boot
38How to check the memory status of the system?
You can use the ‘free’ command to check the memeory status of the system.
$ free -m // Displays the output in MB
$ free -g // Displays the output in GB
39How to log in as root in Linux from the terminal?
— The ‘su’ command can be used to switch user account to root user (superuser).
$ su root
# apt-get update
— the ‘sudo’ command can be used to execute only that command as root user.
$ sudo apt-get update
40How you can run a Linux program in the background simultaneously when you start you Linux server?
— By using the ‘nohup’ command, the process will run in the bacground.
— The process receiving the NOHUP signal will be terminated when you log out of the program, which was used to invoke it.
41Which daemon tracks events on your system?
— The syslogd daemon tracks the system inormation and saves it to specified log files.
42What is partial backup?
— When you select only a portion of you file hierarchy or a single partition for back up, it is called partial backup.
43What is an Inode?
— Contents of the file will be stored in Data blocks.
— Whereas, information about that file will be stored in Inode.
— The information stored would be:
—- File-size
—- Mode/permission (protection)
—- Owner ID
—- Group ID
—- Number of hard links to the file
—- Time last accessed
—- Time last modified
—- time Inode last modified
44Which command is used to set a processor-intensive job to execute in less CPU time?
— Priority of the jobs con be changed by using the ‘nice’ command.
— Syntax:-
nice [OPTION] [COMMAND [ARG]…]
— Priority ranges from -20 to 19 where, -20 is the highest priority and 19 is the lowest priority.
45What are shadow passwords? And how are they enabled?
— Shadow passwords are given for better system security.
— Every user’s password will be stored in /etc/passwd file.
— By implementing shadow passwords, all passwords will be stored in encrypted form in a new file: /etc/passwd
— Passwords in the original file will then be replaced with ‘x’.

Related Article

Migrate VM

How to convert OVA image to QCOW2 format on Linux

Question: I have downloaded a virtual appliance packaged in OVA format. I want to convert the OVA image to QCOW2 […]

Linux-Interview-Questions

Linux Interview Questions

S. No Notes 1 What is Linux? Linux is an open-source operating system inspired by UNIX.It was first introduced by […]

software package management systems

List of software package management systems

List of software package management systems APT- Advanced Package Tool, or APT, is a free-software user interface that works with […]