Linux Advanced Interview Questions

In this article, we test our Linux knowledge by going over 60 advanced multiple choice questions for Interviews.

1. Which command is used to handle the character stream by duplicating its input?
(a) tee
(b) tree
(c) ls
(d) tty

Ans: (a)
Explanation: The tee command is used to handle a stream of characters by duplicating its input. The tree command is used to recursively list directory contents on a tree-like structure. The ls command is used to list files and directories in a directory. The tty command prints the file name of the terminal connected to standard input.

2. What can be used when backspace is NOT working?
(a) CTRL + E
(b) CTRL + R
(c) CTRL + H
(d) CTRL + L

Ans: (c)
Explanation: We can use (c) to erase text on the Linux terminal when backspace is not working. CTRL + E is used to move to the end of a command line. CTRL + L is used to clear the terminal. CTRL + R is used to start a search on the terminal.

3. Can two users in Linux have the same login name?
(a) Yes
(b) No
(c) Not sure
(d) None of the above

Ans: (a)
Explanation: Linux is a multiuser operating system and therefore in a Linux operating system two users with the same login name can log in to the system at the same time on the same network.

4. What is the function of the script command in Linux?
(a) To record terminal sessions
(b) To record scripting sessions
(c) To record script execution
(d) None of the above

Ans: (a)
Explanation: The script command is used to record login sessions to a file. It can record keystrokes, outputs, and error messages. When executed terminal inputs and outputs are saved in a typescript file. It is commonly used by admins to record the outputs of a command to troubleshoot issues involving software installation among others.

5. In Linux, what command is used to send and receive mail?
(a) mailx
(b) mesg
(c) wall
(d) talk

Ans: (a)
Explanation: To send a message to bob@protonmail.me we write; mailx bob@protonmail.me (hello bob).
The talk command allows users to have an interactive chat with other logged-in users on a Linux system.
The mesg command is used to allow or deny messages in the terminal, here we use -n or -y to either deny or allow messages.
The wall command is used to send a message to all logged-in users.

6. What are escape sequences in Linux?
(a) special characters to escape sequences
(b) special characters prepended with a backslash
(c) special characters prepended with a slash
(d) None of the above

Ans: (b)
Explanation: Escape sequences are special characters prepended with a backslash, they are used to change the state of a computer or peripheral devices attached to it.

7. What is returned when nohup command is used?
(a) PPID
(b) PID
(c) UID
(d) GID

Ans: (b)
Explanation: The shell returns the process ID when we use the nohup command. PPID represents a parent process ID, PID is the ID of a process and UID is the unique ID of a Linux user. GID is a unique number that is used to represent a group of Linux users.

8. Which shell supports background jobs without the need for the nohup command?
(a) Korn
(b) sh
(c) Zsh
(d) Bash

Ans: (d)
Explanation: In the bash shell, we can run commands in the background even after the user has logged out.

9. How can we kill the last background job in Linux?
(a) Kill -1
(b) Kill $
(c) Kill!
(d) Kill $!

Ans: (d)
Explanation: To kill the last background job in Linux we execute command (d). $! holds the PID of the last background job in Linux.

10. Which command is used to set process priority in Linux?
(a) nice
(b) ps
(c) ps priority
(d) None of the above

Ans: (a)
Explanation: The nice command allows us to change the scheduling priority of processes in Linux. If a process has a higher priority then more computational resources are dedicated to that process. The nice command is used to modify a process' priority.

11. Which command is used to kill a process?
(a) SIGKILL
(b) CTRL + C
(c) kill
(d) Kill -9

Ans: (c)
Explanation: The kill command is used to prematurely terminate a process in Linux.
SIGKILL is a signal in Linux. When triggered a process is immediately terminated. Its signal number is 9. For example, to kill a process with the PID of 1121 we can write;

$ sudo kill -9 1121

CTRL + C kills a process by calling SIGINT signal, CTRL + Z kills a process by calling SIGTSTP signal.

12. Which is NOT a valid escape sequence in Linux?
(a) \d
(b) \t
(c) \n
(d) \v

Ans: (a)
Explanation: \d is not a valid escape sequence in Linux. \t is used for tabs, \n for new lines, \v for vertical tabs. Others include \r for return, \e for an escape character, \b for a backspace, \a for an alert

13. What does SIGTERM do in Linux?
(a) Start a process
(b) Suspend a process
(c) Terminate a process
(d) Restarts a process

Ans: (c)
Explanation: SIGTERM (15) is used to terminate a process in Linux. Other common Linux signals include SIGINT(2) issued to interrupt a process, SIGQUIT(3) to quit a process, SIGFPE(8) issued when an illegal mathematical operation is performed, SIGALRM(14) for an alarm, SIGHUP(1) issued in the death of a controlling process.

14. Which is NOT part of inode content?
(a) file type
(b) file permissions
(c) file timestamps
(d) file name

Ans: (d)
Explanation: The name of the file is not part of the contents of the inode contents. Linux file systems rely on inodes. An inode does not store actual data rather they store metadata that can be used to locate the data itself.

15. Which command can we use to delete an empty directory in Linux?
(a) rmdir
(b) mkdir
(c) rm
(d) touch

Ans: (a)
Explanation: To remove an empty directory we use command (a). To remove a Non-empty directory we use the rm -rf command. The mkdir command is used to create a new directory. The touch command is used to create a new file.

16. Which two commands have the same output?
(a) pwd and echo $HOME
(b) uname and echo $HOME
(c) pwd and echo $ENV
(d) None of the above

Ans: (a)
Explanation: Both commands will print out the current working directory. The PWD(print working directory) prints the current working directory so does $HOME. $HOME is an environment variable. Environment variables are a set of dynamic values used by shell applications.

17. Which command can we use to kill a login shell in Linux?
(a) kill -s KILL 0
(b) kill -9 $$
(c) kill 0
(d) killall

Ans: (a), (b)
Explanation: We can kill the login shell by using either command (a) or command (b). The killall command is used to kill multiple related processes created by a shell. The kill 0 command kills a process with PID 0. The -s option is used to pass the signal name and number. Here we pass signal KILL and number 0 representing process 0.

18. Which command can we use to find out how much space a file or directory is using in Linux?
(a) du
(b) fdisk
(c) sfdisk
(d) cfdisk

Ans: (a)
Explanation: The du(disk usage) prints out the disk usage by recursively examining the structure of the directory.
fdisk command in Linux is used to create and manipulate the disk partition table.
The sfdisk command is used similarly to the fdisk however it has additional functionalities e.g displaying the size of each partition in MBs
The cfdisk command serves as a partition editor. It has an interactive UI and it is used to list existing partitions. It can also be used to create or modify partitions. Other commands to check disk partitions include parted, df, pydf, lnxi, hwinfo, lsblk, blkid.

19. Among the following filtering commands in Linux. Which is the MOST powerful?
(a) head & tail
(b) grep
(c) sed
(d) awk

Ans: (d)
Explanation: Apart from perl, awk is another powerful text filtering tool in Linux. Awk is used to scan for patterns. Sed is a stream editor used for text filtering. Grep highlights matching patterns in a file. The head and tail commands display the first and last parts of a document. We can use then with the -n option to specify the number of lines we are interested in showing.
We also have sort command, fmt command, uniq command, pr command among other text filtering commands.

20. Which command is used to run background jobs?
(a) nice
(b) fg
(c) nohup
(d) None of the above

Ans: (c)
Explanation: When we prefix nohup to a command the process will run even after a user logs out of the system. When we run processes in the terminal, they are terminated once we exit the terminal, the nohup command is used to run processes in the background even after exiting the terminal.

21. Which command can we use to gain superuser privileges?
(a) switch user
(b) sudo
(c) su
(d) None of the above

Ans: (c)
Explanation: The su (switch user) command is used by a user to change their privileges. To invoke a login shell we can run the su command prepended with '-' or 'l' or '--login'.

22. Which is NOT a use for the cat command?
(a) appending
(b) prepending
(c) displaying
(d) creating

Ans: (b)
Explanation: We cannot prepend using the cat command. We can append, create new files, or display file contents. To append with cat command we write;

$ cat >> file.txt

To create a new file we write;

$ cat > file.txt

To view file contents we write;

$ cat file.txt

23. Which command is used to make a script executable?
(a) chmod +x
(b) chmod +rw
(c) chmod +w
(d) chmod +r

Ans: (a)
Explanation: To make a script executable, we use command (a). rwx represents read, write, or execution rights of a file. If a file/directory has all three then it can be read, written to, or executed as a program.

24. What is the correct definition of a shell script?
(a) A group of commands in a file
(b) A programming language
(c) An interpreter
(d) None of the above

Ans: (a)
Explanation: A shell script is a series of Linux commands. To run them we execute the file with root privileges. Shell scripts are useful when system admins try to avoid repetition, for example, it is wise for a system admin to store configuration commands in a shell script to avoid having to remember them every time a new user in an organization needs a machine setup.

25. What is the default delimiter used by the cut command?
(a) slash
(b) underscore
(c) space
(d) tab

Ans: (d)
Explanation: The cut command cut fields using the tab delimiter by default. Delimiters are commonly used with text filtering commands whereby after filtering we need to print a readable output. A delimiter specifies how columns are separated in a text file. We can separate columns with commas as they are in .csv files or tabs, or '|' to get a table-like structure.

26. Which command is used to extract columns from a file?
(a) cut
(b) col
(c) cat
(d) printf

Ans: (a)
Explanation: The cut command accompanied by the -c option is used to list the column numbers delimited by a comma.
The printf command is used to print a string in a specified format. The cat command can be used to create, append to or view a file in Linux.

27. Which is NOT a system management command in Linux?
(a) systemctl
(b) system
(c) init
(d) sudo

Ans: (b)
Explanation: The system function is used to run Linux commands in awk. The systemctl command is used to manage system services, processes, and configurations. The sudo command is used to execute commands with elevated privileges. The init command is used to initialize and control processes.

28. How many Linux command categories are there?
(a) 1
(b) 3
(c) 4
(d) 2

Ans: (d)
Explanation: In Linux commands can either be internal or external. External commands exist independently in the /bin directory. Internal commands are built into the Linux shell.

29. What is the name of the Linux windowing system?
(a) Red hat
(b) Linux
(c) X Window System
(d) Debian

Ans: (c)
Explanation: X is the Linux windowing system. A windowing system is a software that uses a windowing model on top of a basic display layer. Desktop UNIX systems use X11 windowing system as their default.

30. What command can we use together information about a system?
(a) uname
(b) whois
(c) whoami
(d) nslookup.

Ans: (a)
Explanation: The uname command prints out the name, version, and operating system among other system information.
The whois command is used to get information about a domain. The whoami command prints the currently logged-in user. The nslookup command queries DNS servers for information on a specific domain.

31. In Linux, options have a '-' before them.
(a) True
(b) False
(c) Both
(d) None of the above

Ans: (a)
Explanation: In Linux we prepend options with a hyphen. Most options in Linux have a '-' before them. It is to indicate that it is a command option. We use a single hyphen when we want to chain multiple options together for example;

$ rm -rf file.txt

Above we chain the recursive option and the force option using a single hyphen.

32. What shortcut can we use to resume a suspended terminal in Linux?
(a) CTRL + s
(b) CTRL + q
(c) CTRL + xx
(d) CTRL + a

Ans: (b)
Explanation: To enable keyboard output on the terminal we press CTRL + q. CTRL + a is used to move to the start of the command line. CTRL + xx switches the cursor position between the beginning of the command line and the current position. CTRL + s does the opposite of CTRL + q.

33. Does perl have an interpretive mode?
(a) Yes
(b) No
(c) Neither
(d) Maybe

Ans: (a)
Explanation: Perl has an interpretive mode. A script is first compiled and then executed. Perl is a general-purpose interpreted open source programming language. It can also be Object-oriented and is commonly used for processing text in Linux systems.

34. What key shortcut can we use to erase a whole line of command if we realize it has mistakes?
(a) CTRL + p
(b) CTRL + h
(c) CTRL + u
(d) CTRL + d

Ans: (c)
Explanation: When writing long complex commands, we press CTRL + u to erase the entire line. CTRL + d kills the currently open terminal. CTRL + _ undoes the previously executed command. CTRL + h removes a character before the cursor.

35. Which command is used to display the date in Linux?
(a) date
(b) cal
(c) None of the above
(d) time

Ans: (a)
Explanation: We use the date command to print the system date and time in Linux. The time command is used to measure execution time. For example, we can use it to time how long a program executes for. The cal command is used to print the calendar in most Linux systems.

36. Which command is used to display the calendar in Linux?
(a) date
(b) cal
(c) None of the above
(d) time

Ans: (b)
Explanation: We use the cal command to print out the calendar in Linux. The time command is used to measure execution time. For example, we can use it to time how long a program executes for. The date command is used to print the system date and time.

37. Which character is appended to the command so they can run in the background?
(a) ?
(b) &
(c) !
(d) @

Ans: (b)
Explanation: We append '&' to the end of a command so that it can run in the background and free up the terminal. Running commands in the background allows us to free up the terminal so we can run subsequent commands. However, if we close the terminal, the process is terminated, to prevent this we use the nohup command.

38. What command can we use to print the date in a dd/mm/yyyy format?
(a) date +"%d/%m/%Y"
(b) date +"%h %m"
(c) None of the above
(d) date +%m

Ans: (a)
Explanation: To print the date in dd/mm/yyyy format we write; date +"%d/%m/%Y" The date command in Linux prints the system date and time.

39. Which key combination can be used to decrease the terminal font size in Linux?
(a) CTRL +
(b) CTRL -
(c) None of the above
(d)

Ans: (c)
Explanation: We use 'CTRL -' to decrease the font size of a terminal and 'CTRL +' to increase the font size of a terminal.

40. The key "!!" will
(a) Execute the last command
(b) Moves to the next command
(c) Undoes a previously executed command
(d) Performs a reverse search

Ans: (a)
Explanation: By executing the command !!, we will be executing the last executed command.

41. The command ls -lh will;
(a) List all files starting with letter h
(b) List all files in a human-readable format
(c) List all files and file sizes in a human-readable
(d) List all files owned by the logged-in user.

Ans: (c)
Explanation: We pass the -lh option to list files and their sizes in a human-readable format.

42. The command ls -R will;
(a) List all files and directories recursively
(b) List all files recursively
(c) List all files and directories in reverse
(d) List all directories with a '/' at the end.

Ans: (a)
Explanation: By using -R we recursively list all files and directories and their subdirectories and files. To list directories with '/' appended, we use the -F option.

43. The command ls -r will;
(a) List all files and directories recursively
(b) List all files recursively
(c) List all files and directories in reverse
(d) List all directories with a '/' at the end.

Ans: (a)
Explanation: At times when the files and directories are too much to fit into a screen, we can reverse the listing to get the files and directories with ending alphabets first.

44. The command ls -lS will;
(a) List all files and directories in a sorted order
(b) List all files recursively
(c) List all files and directory information
(d) Display the inode number

Ans: (a)
Explanation: The -lS will list files and directories in a sorted manner. To display the inode number we use the -i option with the ls command. We use -ld command line option with the ls command to list directory details.

45. The command cd will;
(a) Change the current working directory to the root directory
(b) Change the current working directory to the home directory
(c) Change the current working directory to the Documents directory
(d) Concatenate a file.

Ans: (b)
Explanation: we can change the current working directory to the home directory by executing the cd command without any options. To change to the home or Documents directory we need to pass the path. The cat command is used to concatenate files.

46. The rmdir command will;
(a) Remove an empty file.
(b) Remove an empty directory
(c) Remove a directory with contents
(d) Remove a user

Ans: (b)
Explanation: We can only use rmdir to remove empty directories otherwise we should use rm -rf command. To remove a user we use the userdel command. We can use the rm command to remove an empty file.

47. The command 'grep -i "search_string" file.txt' will;
(a) Run a case insensitive search
(b) Return only lowercase 'search_string'
(c) Return only uppercase 'SEARCH_STRING'
(d) Return the first occurrence of the search string

Ans: (a)
Explanation: We use the -i option to run case insensitive commands in Linux. We can search for uppercase or lowercase strings by using the default grep command without any options.

48. The command ls -a will;
(a) List all open files/processes
(b) List all files including hidden files
(c) List files beginning with a
(d) List directory contents

Ans: (b)
Explanation: The ls command will list all files including hidden files. To list all open files we use the lsof command. To list files beginning with a pattern we will pipe ls command output to the grep command. To list directory contents, we have to pass a file name as the argument.

49. The command 'tail -n 10 file.txt' will
(a) Print the last 10 characters in file.txt
(b) Print the first 10 characters in file.txt
(c) Print the first 10 lines in file.txt
(d) Print the last 10 lines in file.txt

Ans: (d)
Explanation: The tail and head command followed by the -n option and a number prints n lines in a file that is passed as an argument.

50. The command 'chmod + w' will
(a) Grant modification permissions
(b) Grant execute permissions
(c) Give write permissions
(d) Give read permissions

Ans: (c)
Explanation: By using 'w' we will be granting write permissions. To grant read permissions we use 'r' and to grant execute permissions we use 'x'.

51. The shortcut CTRL + G will;
(a) Suspends the terminal
(b) Exit histoiry search mode
(c) Execute the last command
(d) Ends history search at the current command

Ans: (b)
Explanation: CTRL + G will exit the history search mode. We use CTRL + Z to suspend a terminal, !! to execute the last command, and CTRL + J to end the history search at the current command.

52. In VIM the key 'h' will;
(a) Move the cursor to the top
(b) Move the cursor to the right
(c) Move the cursor to the bottom
(d) Move the cursor to the left

Ans: (d)
Explanation: 'h' moves the cursor right, j - down, k - up, and l - right.

53. In VIM the key '0' will;
(a) Jump to the start of the line
(b) Jump to the start of the file
(c) Jump to the end of the line
(d) Jump to the end of the file

Ans: (a)
Explanation: To jump to the end of the line we use '$'. We can use page up and page down to jump up and down the start and end of a file.

54. In VIM the key 'zz' will;
(a) Move the cursor the end of the file
(b) Move the cursor to the end of a line
(c) Move a cursor to the center of the screen
(d) Move the cursor to the leftmost point of the screen

Ans: (c)
Explanation: zz centers a cursor in Vim. We can Either use arrow keys of h, j, k, and l to navigate through VIM.

55. In VIM the key 'i' will;
(a) Insert below the cursor
(b) Insert after the cursor
(c) Insert at the beginning of the line
(d) Insert before the cursor

Ans: (d)
Explanation: o is used to append below the current line, O to append above the current line. I inserts at the beginning of a line.

56. The command !^ will;
(a) Undoes the previously executed command
(b) Cycles to the next command
(c) Executes the last executed command
(d) Substitute the first argument of the last command in the current command

Ans: (d)
Explanation: For example we can write;

$ echo 8.8.8.8

# then reuse the argument in another command as follows

$ ping !^

We use the up and down arrow keys to cycle through previously executed commands.

57. In VIM the key 'CTRL + t' will;
(a) de-indent a line on shift width
(b) indent a line one shiftwidth
(c) begin a new line in insert mode
(d) delete a word before the cursor

Ans: (b)
Explanation: To de-indent a line on shiftwidth we use CTRL + d. CTRL + j is used to begin a new line insert mode. CTRL + w deletes a work before the cursor in insert mode.

58. The command !1888 will;
(a) Forks a process with PID 1888
(b) Execute a process with PID 1888
(c) Execute a command with command ID 1888
(d) Executes a command with a history number 1888

Ans: (d)
Explanation: !888 will execute the command with the history number of 1888. Process IDs are different from history IDs.

59. The command '!l' will;
(a) Execute the last executed command
(b) Execute any previous command starting with 'l'
(c) Close the terminal
(d) Reboot the system

Ans: (b)
Explanation: To execute a previously execute command starting with the letter 'l' we write;

$ !l

To reboot a Linux system we use the reboot command. To execute the last executed command we use !! command.

60. In VIM the key 'r' will;
(a) Replace a character
(b) Replace a word
(c) Delete character and substitute text
(d) Delete line and substitute text

Ans: (a)
Explanation: We can replace more than a single character using CTRL + R. CTRL + s deletes a character and substitutes it with text. CTRL + S delete a line and substitutes it with text