0% found this document useful (0 votes)
244 views10 pages

1.1 Top Linux Interview Q&A PDF

This document provides answers to common Linux interview questions. It covers topics such as executing multiple commands from the command line, using find and grep commands to search for files and text, checking memory and process status, appending and viewing files, installing software and libraries, and differences between Linux, UNIX, BASH, and DOS. The questions help explain fundamental Linux concepts and commands like the kernel, desktop environments, root user, command line interface, and empty directories.

Uploaded by

maheshsekar25
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
244 views10 pages

1.1 Top Linux Interview Q&A PDF

This document provides answers to common Linux interview questions. It covers topics such as executing multiple commands from the command line, using find and grep commands to search for files and text, checking memory and process status, appending and viewing files, installing software and libraries, and differences between Linux, UNIX, BASH, and DOS. The questions help explain fundamental Linux concepts and commands like the kernel, desktop environments, root user, command line interface, and empty directories.

Uploaded by

maheshsekar25
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 10

Top Linux Interview Questions & Answers

1) How do you execute more than one command or program from a single
command line entry?
(Example directory used: /home/user1/STUDENT).

Use a semicolon symbol.


3 commands on one line:
ls -l; cd ..; ls -a STUDENT
The above will be executed one after the other, in the order specified.

2) Write a command that will look for files with an extension "c", and has the
occurrence of the string "banana" in it.
(example used: /home/user1/STUDENT/fruit.c)
find ./ -name "*.c" | xargs grep –i "banana"

3) Write a command that will display all .txt files, including its individual
permission.
(example used: /home/user1/STUDENT)
ls -al *.txt <<< only searches inside current directory
find ./ -name "*.txt" <<< searches ALL directories etc.

4) Write a command that will do the following:


-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 “banana” in the files.
(example used: two .c,v files in STUDENT folder)
find ./ -name "*.c,v" | sed 's/,v//g' | xargs grep "banana"

5) What is wrong with each of the following commands?


a) ls -l-s
b) cat file1, file2
c) ls - s folder2

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 indicator: ls –s folder2
6) What is the command to calculate the size of a folder?
du –sh folder1

7) How can you find the status of a process?

Via command:
ps ux

8) How can you check the memory status?

Use the commands:


free -m >>> to display output in MB
free -g >>> to display output in GB

9) How can you append one file to another in Linux?


Use command: cat file2 >> file1
The operator >> appends the output of the named file or creates the file if it is not created. While another
command cat file1 file2 > file3 appends two or more files to one.

10) How you can find a file using the Shell Terminal?
Use command: find . –name "file2.txt"
It will look inside the current directory for a file called “file2.txt”

11) How can you create a folder using the Shell Terminal?
Use command: mkdir
Example: mkdir folder3

12) How can you view a text file using the Shell Terminal?
Go to the specific folder where the text files are located by using the command cd and then type less file1.txt

13) How do you enable curl on Ubuntu LAMP stack?


First, install libcurl, then use the following command: sudo/etc/init .d /apache2 restart or sudo service
apache2 restart

14) How do you enable root logging in Ubuntu?

What is root logging?


Answer: Whenever you are logged in as root, or using sudo, if root logging is active, it will log the related root
actions. This means that all executes of files, write actions and changes to attributes are recorded in a log file.

Use this command:


sudo sh-c 'echo "greater-show-manual-login=true" >>/etc/lightdm/lightdm.conf'
(The above command is for the lightdm display manager. If you use kdm or gdm display manager, then the
command will be slightly different. I leave this to you to figure out!)
15) How do you uninstall the libraries in Linux?
Use command sudo apt-get remove library_name

16) What is Linux?

Linux is an operating system based on UNIX and was originally created by Linus Torvalds(Linus + Unix = Linux).
It is based on the Linux Kernel and can run on many different hardware platforms. Linux has its own mascot, a
penguin figure named Tux.

17) What is the difference between UNIX and LINUX?

Unix 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.

18) What is BASH?

BASH is short for Bourne Again SHell. Bash is a Unix (and Linux) shell and command language written by Brian
Fox for the GNU Project as a free software replacement for the Bourne shell(represented by /bin/sh). Bash is a
command processor that typically runs in a text window where the user types commands that cause actions. It's
similar to the command prompt or powershell in Windows, but probably more powerful. 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.

19) Define Linux Kernel?

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.

20) What is LILO?

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.

21) Define swap space?

Swap space is a certain amount of physical disk space used by Linux to temporarily hold some concurrently
running programs. Swap space is generally used when the RAM memory is full, i.e. when RAM runs out of
memory space to hold all programs that are executing. Swap space is much slower than RAM, and therefore the
programs it executes are also much slower. Small price to pay to prevent your machine from freezing up, which
can happen if RAM gets overloaded and there's no swap space to fall back onto. Swap space is generally
useful/relevant for low-spec machines with very little RAM memory available, i.e. around 4gb RAM or less. For
machines with 16gb+ RAM, swap space should really never be necessary, unless it's a high resource load
server...
22) What is the advantage of open source?

Usually this concept is applied to software(or hardware) that people can freely modify and share because the
design and/or source code is publicly legally accessible/available. 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.

23) What are the basic components of Linux?

Kernel > maintains all vital abstractions(hardware, etc) of OS, as well as virtual memory and other processes.
System libraries > libraries contain functions used by applications, and system libraries allow interrelation
through the kernel.
Shells > user interface/access to the kernel via user commands, to execute kernel functions.
GUIs > graphical user interface, which activates the desktop and enables the use of the mouse, etc.
System Utilities > system programs that can execute specific managing tasks.
Applications/Application Manager > various applications that can be used by user for various different tasks.

24) Does it help for a Linux system to have multiple desktop environments
installed?

In general, one desktop environment, like KDE or Gnome or Lightdm, is good enough to operate without issues.
It's all a matter of personal preference for the user, although the system allows switching from one environment
to another usually from the login screen. Some programs will work in one environment and not work in the other,
so it could also be considered a factor in selecting which environment to use, but generally most programs will
work in any Linux desktop environment.

25) Main differences between BASH and DOS?


- BASH commands are case sensitive; DOS commands are not;
- In BASH, / character is a directory separator and \ acts as an escape character. In DOS, / is 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 characters for
the extension. BASH follows no such convention.

26) What is the root account?

It's basically a systems administrator account for Unix/Linux-like systems, and allows you full control of the
system, including the kernel(especially from the BASH). You can create and maintain user accounts, assign
different permissions for each account, etc. Similar to the admin user for Windows, but more powerful, possibly
with more full control than a Windows admin account. It's the default account that comes with any Linux
installation.

27) What is CLI?

Short for Command Line Interface. This interface allows the user to type declarative commands to instruct the
computer to perform specific actions. CLI offers greater flexibility than GUI. However, other users who are
already accustomed to using GUI often find it difficult to remember BASH commands including attributes that
come with it. System administrators and root users regularly use the CLI.
28) What is GUI?

Short for Graphical User Interface. This interface is more visually oriented and therefore makes use of images
and icons that users click on and manipulate as a way of communicating with the computer. Instead of having to
remember and type BASH commands on the CLI, the use of graphical elements makes it easier to interact with
the system for most users, as well as adding more attraction through images, icons, and colors.

29) What does a nameless (empty) directory represent?

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.
But, nameless doesn't automatically mean empty. For example, the character / represents root directory in
Linux, whereas any other system directory like home would be written like this /home. Or sys and bin would look
like this:
/sys
/bin
So, the root directory of Linux isn't technically nameless, it just doesn't have a name next to the / character, but
we still call it root. It is exactly the same concept as the C:\ drive in Windows, which is the root directory of
Windows, with a trailing backslash character after the C: which normally indicates the physical partition where
Windows system files are installed. In this case we can say that C:\ is also a nameless directory. Also, this
nameless root directory technically isn't empty, because it will always contain at least some system sub-
directories and even some files within the root directory, example: /vmlinuz.old

30) What is the pwd command?

Short for “print working directory”.


This command just prints out on the shell terminal screen what your current working directory is, including the
full path name.

31) What are daemons?

Linux or Unix programs that run as background processes. Their names usually end with the letter “d”. Some
examples of daemons:
httpd > handles apache server
sshd > handles ssh remote access
Daemons that are started automatically by the system, are usually started at boot time.
Their main task is to listen for service requests and to react on these requests. After the service is completed,
the daemon is disconnected and waits for further requests.

32) How do you switch from one desktop environment to another, such as
switching from KDE to Gnome?

Must have these two environments already installed, then just log out to get to the graphical login screen. From
there, type your login ID and password and choose which session type/desktop environment you wish to load.
This choice will remain your default until you change it to something else.

33) Name the different types of permissions under Linux?

Read: users may read the files or list the directory. Character “r”
Write: users may write to an existing file or create & write to new files in a specific directory. Character “w”
Execute: users may run an executable file or lookup a specific file within a directory. Character “x”
34) How does case sensitivity affect the way you use commands?

Linux BASH commands are case sensitive and are considered identical only if every character is encoded as is,
including lowercase and uppercase letters. This means that CD, cd, and Cd will be seen as three different
commands on the BASH shell.
However, in Linux, you can create aliases of system commands. For example, lets use the change directory
command “cd”. Lets assign some random alias to it with the following alias command:
alias cd="CD"
Now the system will see “cd” and “CD” as the same command, because “CD” alias will point to “cd” command.
So remember, in this example “CD” is not a command, it is only an alias for another command, “cd”. Also note,
that IF “CD” was already a system command, we would not be able to use it as an alias for another command.

35) What are Linux environment variables?

Linux environment variables act as placeholders for information stored within the system that passes data to
programs launched in shells or sub-shells. Available to all shells. These variables are dynamic values which
affect the processes or programs on a computer. A shell variable is a special variable that is set by the shell and
is required by the shell in order to function correctly.

36) What are the different modes when using vi editor?

The vi editor is the most popular and classic text editor in the Unix & Linux family. There are several other good
text editors like nano, gedit, and so on.
Modes:
Command mode > when vi starts up. Enables you to type commands, or navigate through the file with the
arrow keys, etc.
Insert mode > this is the mode that allows you to insert new text or edit the file.
Last Line mode(escape mode) > Activated by typing colon “:” character. This mode enables you to perform
common tasks such as saving files, executing commands, etc.

37) Is it possible to use shortcuts for a long path name?

Yes it is possible. Filename expansion allows you to do this by using the TAB key. For this to work the path must
be unique, and the shell you're using must support this feature.

38) What is redirection?

The basic workflow of any Linux command is that it takes an input and gives an output.
The Redirection feature in Linux can be used when executing a command to enable you to change the standard
input/output devices, i.e. changing the way from where commands read input to where commands send output.
Therefore it can also be used to direct an output as an input to another process.
Meta characters are typically used for redirection.
The standard input (stdin) device is the keyboard.
The standard output (stdout) device is the screen.
39) What is the grep command?

grep = "global regular expression print"


grep is a search filter command used for pattern based searching of plain-text data sets/files for lines that match
a regular expression or specific pattern of characters, and outputs all lines that contain that pattern.
Its name comes from the ed command g/re/p, which has the same effect: doing a global search with the regular
expression and printing all matching lines.
It makes use of options and parameters that are specified with the command line and applies this pattern in
searching the required file output.

40) In what common situation will a command you used previously give a
different result now?

Case sensitivity. Maybe you used “ls” before, and now you are using “LS” or “Ls”.
Also, using some commands in different directories will give different results that depend on the contents of the
specific directory.

41) What is the following directory used for?: /usr/local

/usr/local is a place where software usable by all users can be installed locally by an administrator. 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.

42) How do you terminate an ongoing process?

Every process in the system is identified by a unique process id or pid. Use the kill command followed by the pid
to terminate that process. To terminate all process at once, use kill 0. There are some parameters you can also
add to this kill command, if necessary.

43) How do you insert comments on the shell command line?

Comments are created by typing the # symbol before the actual comment text. This tells the shell to completely
ignore what follows.
For example:
# The shell will ignore this comment, including all comments below
# ls
# cd
# mkdir

44) What is command grouping?

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_file1” to a second file named “output_file2”, you can apply command grouping
as follows:
(date cat output_file1) > output_file2
Additionally:
Parentheses is useful only if you are doing redirection, i.e. when you are sending the results of the commands,
within the parentheses, to some final destination, like a file.
Otherwise, if you are not doing any redirection of output from commands, you can just use "&" and "wait" like so:
cmd1 &
cmd2 &
wait
cmd3 &
cmd4 &
wait
wait allows the background process to complete, before it allows the shell to continue with the next commands.
Alternatively, you can also use the semicolon ; instead of "wait". Same function.
Placing a list of commands between parentheses causes a subshell environment to be created, so variable
assignments do not remain in effect after the subshell completes.
( cmd1 & cmd2 )
Placing a list of commands between curly braces causes the list to be executed in the current shell context. No
subshell is created. The semicolon (or newline) following list is required in this case.
{ cmd1 & cmd2; }

45) How do you launch a Linux shell to issue commands?

One backup method is to press Ctrl-Alt-F1. This will provide a command line interface (CLI) from which you can
run commands as needed. This is especially useful if your Linux GUI or Desktop environment is not accessible
for some reason from the login screen, or if the login screen did not even load. Often, you only need access to
the default shell via ctrl-alt-f1 to fix the issue with several relevant commands.
But normally, you would probably launch the shell from within your Linux desktop environment via the
applications menu, or via a shortcut icon that you created. Either way, you will usually find the shell program if
you search the menu for “terminal”, or “shell”, or “bash”. Try “terminal” first.

46) How do you check memory usage of your Linux system?

Typical commands for current memory use are:


free
free -m
free -h
vmstat
top
htop
Can also use the "concatenate" command for memory usage information:
cat /proc/meminfo
This is the total memory Linux thinks it has available to use.

47) What is the typically recommended size for a swap partition under a
Linux system?

The recommended size for a swap partition is twice the amount of physical(RAM) memory available on the
system. If this is not possible, then the minimum size should be the same as the amount of physical memory
installed.
For example: if your computer has 4gb physical memory(RAM), then your swap partition should be 8gb in size.
Having said that, there are two types of swap space:
swap partitions
swap file
The swap file has become the recommended method in most cases, but you should always do your own
research first to make sure which method is best for you.

48) What are symbolic links?

A symbolic link, also known as a symlink or a soft link, is a special type of file/entry that points to the actual file or
directory on a disk (similar to a shortcut in Windows).
Symbolic links are used all the time to link libraries and often used to link files and folders on mounted NFS
(Network File System) shares, but can also be used like you would normally use shortcuts in Windows.
The ln command is a standard Linux utility for creating symbolic links:
ln -s <SOURCE> <LINK_NAME>
Create a symbolic link to a file:
ln -s /path/to/file /path/to/symlink
Create a symbolic link to a directory:
ln -s /path/to/directory /path/to/symlink

49) What does Ctrl+Alt+Del key combination do in Linux?

You can perform a system restart, just like in Windows. One difference though is that a reboot is immediate,
without any confirmation message.
You can also reboot your Linux machine via the shell terminal, with command “reboot”, or via the standard menu
path, or by clicking on the shutdown icon on your desktop menu bar, if your Linux has such an icon.

50) How do you refer to parallel port devices such as printers?

In Windows the parallel port is LPT, or LPT1, LPT2 or LPT3, etc.


In Linux you refer to the parallel port as /dev/lp
i.e. as /dev/lp0, /dev/lp1, or /dev/lp2, etc.

51) How are disk drives(hard drives, floppy drives, etc) represented in Linux?

As with Windows and Mac where different drives have different representations, the same applies to Unix/Linux
systems. Each of these operating systems has their own format to represent disk drives.
In Linux, floppy drives are referred to as:
/dev/fd0, /dev/fd1, etc.
IDE hard disks are referred to as:
/dev/hda, /dev/hdb, /dev/hdc, etc. These are physically separate disks.
Whereas disk partitions are referred to as:
/dev/hda1, /dev/hda2, /dev/hda3, /dev/hda4, /dev/hda5, /dev/hda6, etc. These are partitions on the same
physical disk.

52) How do you change file/folder/directory permissions in Linux?

Firstly, you need to be an administrator level user to do this, or the owner of the file/folder/directory.
Permissions are granted using the chmod command.
Commonly used parameters:
+ symbol to add permission
– symbol to deny/remove permission,
used in conjunction with any of the following letters:
u (user), g (group), o (others), a (all), r (read), w (write) and x (execute).
Example:
chmod go+rw file1.txt
Above command grants read and write access to the file “file1.txt”, for groups and others.

53) How to access partitions in Linux?

Partitions in Linux are indicated by a number.


Using disk /dev/hda as example, to represent 4 primary partitions:
/dev/hda1, /dev/hda2, /dev/hda3, /dev/hda4
To represent 2 logical partitions:
/dev/hda5, /dev/hda6
54) What is the maximum permitted length for a Linux filename?

Maximum of 255 characters, excluding the path name.

55) What does a file name, preceded by a dot, mean?


Usually this indicates a hidden file. Normally used for system files and other configuration files that hold
important data or setup info.
Hiding sensitive/important system or configuration files away from normal Linux users makes it less likely to be
deleted by accident, and therefore serves as extra protection against system issues. However, administrator/root
users normally have full access to these files, and should also be careful not to delete or modify them, unless
they know what they're doing.
The following command lists ALL files within a specific directory/folder, including all hidden files which include all
files preceded by a dot:
ls -a

56) What is a virtual desktop?

For people who don't have multiple physical screens set up to expand their desktop environment, the virtual
desktop functionality is available. It serves the same purpose as having multiple physical screens alongside your
main screen/monitor.
So if you only have one physical screen, you can create multiple virtual “screens” or virtual desktops which you
can switch to quickly and easily via one mouse click on your desktop's application bar, the thin bar across your
screen normally found at the bottom of your desktop.
Additionally, it is possible to select which running applications should be available/accessible from all your virtual
desktops, as described below.

57) In Linux, how do you make a running/open application visible &


accessible across all your different virtual desktops?
Upper left-hand corner of an application window you should see an icon that looks like a thumbnail, or pushpin.
Clicking this button will "pin" that application in place, making it visible & accessible in the same position in all
your virtual desktops.

You might also like