Linux Multiple Choice Questions - Part 2
In this article, we test our Linux knowledge by going over 60 multiple choice questions.
1. Which command is used to add a new user in Linux?
(a) userdel
(b) adduser
(c) useradd
(d) usermod
Ans: (a)
Explanation: The userdel command is used to remove a user from a Linux system. The adduser and useradd commands are used to add a new user to a Linux system. While adduser sets up user directories, and other necessary user details easily, useradd creates a new user without adding the directories or complex user configurations. The usermod command allows admins to modify user configurations such as login information.
2. Which command is used to display file contents?
(a) cat >> file.txt
(b) cat > file.txt
(c) echo file.txt
(d) cat file.txt
Ans: (d)
Explanation: To display file contents we concatenate the file by writing; cat file.txt. To append to a file we can use option (a). By using option (b) we will replace file contents. The echo command will just print the text 'file.txt.
3. What does FSF mean?
(a) Free Software Federation
(b) Free Source Foundation
(c) Free Software Foundation
(d) Free Server File
Ans: (c)
Explanation: FSF is a nonprofit organization that promotes the creation, distribution, and amendment of free software programs and applications without any restriction.
4. In Vim, how can we move to the beginning of a line?
(a) :0
(b) 0
(c) :/start
(d) None of the above
Ans: (a)
Explanation: We use 0 to move to the beginning of the line we are editing. We use the '$' to move to the end of a line we are currently editing.
5. In Vim how can we move to the first line in a file?
(a) :$
(b) k
(c) :0
(d) Arrow Up
Ans: (c)
Explanation: To move to the first line of a file we press Esc then :0 followed by the Enter key. To move to the last line we can use :$. Options (b) and (d) are used when we want to move up one line in a file.
6. In Vim how can we move to the last line in a file?
(a) Arrow Down
(b) j
(c) :0
(d) :$
Ans: (d)
Explanation: To move to the last line of a file we press Esc then :$ followed by the Enter key. To move to the first line of a file we use :0. j is used to move down the file by a single line. Arrow down is used to move down a file line by line.
7. Which among the commands can be used to mount a CDROM in Linux?
(a) mount /dev/cdrom
(b) mount /mnt/cdrom
(c) All the above
(d) None of the above
Ans: (c)
Explanation: Both commands (a) and (b) can be used to mount a CD ROM in Linux. Mounting is an action that requires sudo privileges therefore we need to run the command preceded with sudo. To unmount a CDROM or USB we use the umount command.
8. In Vim how can we move to the end of a line?
(a) j
(b) $
(c) 0
(d) l
Ans: (b)
Explanation: We use the '$' to move to the end of a line we are currently editing. We use 0 to move to the beginning of the line we are editing. 'J' is used to move down by one line. 'L' is used to move to the right. '0' is used to move to the start of a line.
9. Which among the following is used to search for a pattern in Vim?
(a) //
(b) :/search
(c) :search
(d) /
Ans: (a)
Explanation: To start a search in Vim we use the '/' character followed by the text we want to search for, As we type in the text, if available all matches will be highlighted. After we have found a match, we can use 'n' key to move through the matches.
10. Which keys can we use to scroll down in Vim?
(a) CTRL + f
(b) CTRL + W
(c) Ctrl + P
(d) Ctrl + J
Ans: (a)
Explanation: To scroll down in Vim we hold CTRL + f and to scroll up we hold CTRL + b. CTRL + W is used to switch between split windows in vim. Ctrl + J is used to move the cursor down by a single line. Ctrl + P is used to move the cursor up one line.
11. Which option is used with the sort command to sort numbers in Linux?
(a) -n
(b) -r
(c) --numeric-sort
(d) -h
Ans: (a), (c)
Explanation: We can use -n or --numeric-sort to sort numbers in a file in Linux. To sort in a reverse order we use the -r option, we can also use --reverse. -h option is used to perform a human-numeric sort for example sorting 2kg, 4kg, 1kg...
12. Which command can we use to view the aspects of a process such as its PID?
(a) htop
(b) ps
(c) top
(d) All the above
Ans: (d)
Explanation: With these three commands we can get information such as the process ID, the user, and the resources the process is consuming among others. The htop command is the top command on steroids. By default, the ps command lists processes, their PIDs, TTys, CMD, and Time, however, we can use options to get more specific information, for example, the -u option can be used to find processes by a specific user in a system.
13. Which command can be used to create three files(file1.txt, file2.txt file3.txt)?
(a) touch file[1,3].txt
(b) touch file{1..3}.txt
(c) touch file[1..3].txt
(d) touch file{1, 3}.txt
Ans: (b)
Explanation: We can create three files, file1.txt, file2.txt, and file3.txt using command (b). The same can also be done for letters for example; file{a..d}.txt file create filea.txt, fileb.txt, and so on.
14. Which command can be used to change the directory to the home directory?
(a) cd
(b) cd ~
(c) mv ~
(d) None of the above
Ans: (a, b)
Explanation: Both a and b can be used to change the directory back to the home directory. The mv command is used to rename or move a directory. If it is renaming it takes the original name as the first argument and the new name as the second argument. If it is moving it takes the original file as the first argument and a location as the second argument.
15. Which key by default is NOT used for up down left right movement in Vim/Vi?
(a) J
(b) K
(c) A
(d) H
Ans: (c)
Explanation: We use H J K L to move left down up right respectively in Vim/Vi. We can also use arrow keys or a mouse if enabled. Option (c), 'A' is used to append from the end of a line.
16. After using the history command to view previous commands, how can we execute a previously executed command using its history number?
(a) 1968!
(b) !1968
(c) 1968
(d) None of the above
Ans: (b)
Explanation: To execute a previously executed command without having to type it out again, we prepend the command with an exclamation mark. In this case, the history number of the command we are looking for is 1968 therefore to execute the command without rewriting or copy-pasting we just write !1968.
17. Which command is used to quit Vim/Vi?
(a) :quit
(b) :q
(c) :q!
(d) All the above
Ans: (d)
Explanation: Commands (a), (b), and (c) are used to quit Vim. We use the exclamation mark if we are forcing a close in an edited file. q and quit are similar, they can be prepended with 'w' to save the file.
18. Which command is NOT used to save in Vim?
(a) :w
(b) :wq
(c) :q
(d) :wq!
Ans: (c)
Explanation: (d) is used to save and force quit. (a) is used to save without closing Vim. (b) is used to save a quit Vim/Vi.
19. Which command is used to sort in Linux?
(a) sorted
(b) sort
(c) None of the above
(d) All of the above
Ans: (b)
Explanation: The sort command in Linux is used to sort a file. Sorted is a python function used for sorting.
20. Which option is used with sort to sort a file in reverse order?
(a) --reverse
(b) -r
(c) -h
(d) -n
Ans: (a), (b)
Explanation: We can use either (a) or (b) to sort a file in reverse in Linux. Choice (c) is used to sort in human-readable data. '-n' is used to sort numbers in a file. We can combine options, for example, we can sort numbers in reverse order using the '-nr' option.
21. Which is the right syntax for the grep command?
(a) grep options pattern
(b) grep pattern filename
(c) grep options pattern filename
(d) grep options filename
Ans: (c)
Explanation: The grep syntax is as follows;
grep [OPTION]... PATTERNS [FILE]...
We use the grep command to search for a pattern in Linux. Once found, grep prints the whole file highlighting matching words.
22. What files are used by TCP wrappers in Linux?
(a) /etc/hosts.allow
(b) /etc/hosts
(c) /etc/hosts.deny
(d) /etc/hostname
Ans: (a), (c)
Explanation: TCP wrappers rely on the configuration files (a) and (c) as the basis for access control in Linux. A TCP Wrapper is a software in the public domain that provides firewall services for UNIX servers and clients.
23. What is the function of TCP wrappers in UNIX servers?
(a) Filtering incoming traffic
(b) Provide domain services such as naming
(c) All the above
(d) None of the above
Ans: (a)
Explanation: A TCP wrapper in Linux filters incoming network traffic. When a server receives an incoming request, it is the job of TCP wrappers to determine if the request should be accepted or rejected. TCP wrappers rely on the hosts.allow and hosts.deny to determine if the client should be allowed to use a given service.
24. Which wild card is used to match any number of characters?
(a) ?
(b) *
(c) [*]
(d) f??t
Ans: (b)
Explanation: To match any number of characters including a single one, we use the '*' wild card. The ? wild card as seen in option (d) is used to match any two characters e.g foot, feet, and so on.
25. Which wild card is used to match a single character?
(a) ?
(b) *
(c) [*]
(d) \
Ans: (a)
Explanation: To match a single character, we use the '?' wild card. We use square brackets to match a range of characters or numbers. A backslash is used as an escape character.
26. Where can we configure a host and allow all connections from all other hosts?
(a) /etc/hosts/hosts.conf
(b) /etc/hosts.allow
(c) /etc/hosts.deny
(d) /etc/hosts
Ans: (b)
Explanation: To allow connections from external hosts we add the host to the /etc/hosts.allow file. TCP wrappers in Linux use this file to determine hosts allowed to access the system. Another file used by TCP wrappers is the hosts.deny file.
27. In Linux which command can, we use to search for a pattern across multiple files?
(a) grep
(b) find
(c) locate
(d) history
Ans: (a)
Explanation: When we use grep to search for a pattern in multiple files, grep will display the lines that match the pattern or file names that contain the pattern. The history command prints a record of previously executed commands.
28. Which wild card is used to match a range of characters?
(a) ?
(b) *
(c) [ ]
(d) .
Ans: (c)
Explanation: We use Square brackets - [] to match a range of characters. The '?' is used to match any single character. Asterisks matches any number of characters. A dot matches any single character. It works similar to a question mark. For more information on Linux wild cards refer to this page.
29. Which among the following is used to access an SMB share on Linux?
(a) smbclient
(b) smbserver
(c) smbstart
(d) None of the above
Ans: (a)
Explanation: An smbclient provides an Ftp-like interface on the command line. SMB(server message block) is software that allows file sharing and printing services across a network. It is installed in a central Linux server, then windows and Linux clients can access share files.
30. Select the first UNIX editor?
(a) Vi
(b) Vim
(c) ed
(d) Emacs
Ans: (c)
Explanation: ed was the first UNIX editor. It could not execute shell commands and could only edit files in the current directory. Vim is an improved version of the Vi editor. Emacs is also a text editor that comes by default in most Linux systems.
31. Which is NOT a feature of UNIX?
(a) user friendly
(b) multiuser
(c) security
(d) multitasking
Ans: (a)
Explanation: UNIX is not a user-friendly system. There is a learning curve involved. A UNIX system is also portable(it can run on different systems), it supports multitasking and multiuser capabilities. It has an extensive library of software packages and distributions. Its file system is hierarchical starting from the root(/) folder down the tree.
32. Which among the following is a text editor in Linux?
(a) Vi
(b) Notepad
(c) None of the above
(d) Word
Ans: (a)
Explanation: Vi is a Linux editor. Vim(vi improved) is commonly used in Linux systems. Other Linux text editors include VIM, Emacs, and Nano among others.
33. UNIX is programmed in __ programming language?
(a) Go
(b) C++
(c) Java
(d) C
Ans: (d)
Explanation: At first UNIX was written in assembly language. Assembly language is hardware specific meaning that it could only run on a specific CPU architecture. Later it was rewritten in a medium-level programming language(C) so it could run on different CPU vendor chips.
34. The UNIX shell script is both a and a ?
(a) compiled, interpreted
(b) scripting, interpreted
(c) compiled, scripting
(d) None of the above.
Ans: (b)
Explanation: UNIX is both an interpreter and a scripting language. An interpreted programming language executes instructions directly without pre-compilation. Shell scripts are interpreted by the Linux kernel. A scripting language is a language that is comprised of commands that get executed one at a time.
35. What is UNIX?
(a) A company
(b) A foundation
(c) An operating system
(d) A programming language
Ans: (c)
Explanation: Unix is a family of multitasking, multiuser operating systems developed at Bell labs by Ken Thompson, and Dennis Ritchie, among others.
36. What happens when grep does NOT find a pattern?
(a) It prints an error
(b) It silently returns
(c) None of the above
(d) It returns the file
Ans: (b)
Explanation: When the grep command does not find a match, it silently returns, otherwise if a match is found, it returns the file with the matches highlighted depending on the options accompanying the command.
37. Which among the directories stores special files in Linux?
(a) /dev/null
(b) /dev/etc
(c) /dev/tty
(d) None of the above
Ans: (a), (c)
Explanation: In Linux, /dev/tty and /dev/null are classified as special files. Both files are present in all Linux systems. In general /dev is where special files and devices are stored in Linux.
38. How do we invoke a Linux built-in calculator?
(a) calc
(b) cal
(c) bc
(d) None of the above
Ans: (c)
Explanation: The bc command is used to invoke a Linux built-in calculator. The cal command prints the calender in most UNIX systems. We execute the bc command without any options. For more options we can write;
$ bc --help
39. Which among the processes is first to run in UNIX?
(a) Bash
(b) shell
(c) authentication
(d) Browser
Ans: (b)
Explanation: The shell process is first to run after the kernel is done setting up. init which is the first process to run with a PID of 1. It is also started by the kernel.
40. Which among the commands is used to create a new process?
(a) ping
(b) fork
(c) mkdir
(d) mkfs
Ans: (b)
Explanation: To create a process in Linux we use the fork system call. It will create an exact copy of the process that invoked it. A fork bomb is a DDoS attack whereby a process replicates itself multiple times with the sole purpose of depleting system resources. This causes starvation and finally crashing. The code is as follows;
$ :(){ :|:& };:
After executing the command, the system will shut down. We can prevent fork bombs by limiting the number of processes that can be started. For this, we use the ulimit command. For example, we can limit the number of processes to 10000 by writing;
$ ulimit -S -u 5000
41. What command do admins use to change permissions of a file in Linux?
(a) chdir
(b) chown
(c) chmod
(d) chage
Ans: (c)
Explanation: We use chmod to change the permissions of a file in Linux. By default, the owner of the file or the super-user is allowed to run the command. The chage command is used to change user password expiry information. The chdir command works similarly to the cd command.
42. Which command is used to copy in Linux?
(a) copy
(b) cp
(c) mv
(d) chdir
Ans: (b)
Explanation: We use the cp command to copy files and directories in Linux. mv command is used to rename or move a file from one directory to another. chdir command is similar to the cd command.
43. What symbols can we use the change the permissions of a hidden file in Linux?
(a) .
(b) *
(c) &
(d) $
Ans: (a)
Explanation: Hidden files in Linux are accessed using the '.' character. This is because hidden files are named with a dot prepended to the file name. For example .env files or .gitignore files or .git directory. To list all hidden files in a directory, we write; ls -a.
44. What command do we use when we want to count words, lines, and characters in Linux?
(a) count
(b) ls
(c) wc
(d) comm
Ans: (c)
Explanation: The wc (word count) command takes in a file and returns the number of words, lines, and characters in the file. The comm command is used to compare two files. ls command lists the contents of a directory.
45. Which command can we use to translate characters?
(a) translate
(b) tr
(c) sort
(d) pr
Ans: (b)
Explanation: The tr command manipulates individual characters line by line. The pr command prepares a file for printing by adding padding such as header and footer information among others.
46. Which command is used to create a child shell in Linux?
(a) sh
(b) mksh
(c) chsh
(d) fork
Ans: (a)
Explanation: sh is a command line interpreter that executes a command that it reads from a command line string. We invoke a child shell by typing sh. chsh command is used to change the current shell. To list all available shells we write;
$ cat /etc/shells
fork command is used to spawn a new process in Linux. Finally, mksh is a command-line interpreter used for interactive and shell scripting.
47. Which among the following commands can we use to prepare a file for printing?
(a) prepare print
(b) cat
(c) print
(d) pr
Ans: (d)
Explanation: By using the pr command we prepare a file for printing. It adds headers, footers, and other text. This command adds suitable headers, footers, and other text including margins, timestamps, and page numbers.
48.Which among the following is NOT a default in all Linux distros?
(a) Graphical User Interface
(b) Kernel
(c) Shell
(d) System calls
Ans: (a)
Explanation: Some Linux distributions such as arch Linux / alpine come without a default graphical user interface installed.
49. What command sod we use when we want to compare files in Linux?
(a) comp
(b) diff
(c) cmp
(d) comm
Ans: (a)
Explanation: To compare two files bytes by byte, we use the cmp command. It displays a mismatch between two files in the terminal. The difference between the two is that comm compares sorted files. Additionally, cmp compares files character by character.
50. Which among the following interacts with the hardware?
(a) shell
(b) kernel
(c) terminal
(d) Graphical User Interface
Ans: (b)
Explanation: The kernel is the core of the OS. It is mostly comprised of routines that communicate with the hardware directly. They are programmed in C.
51. Which command is used to display the beginning of a file?
(a) head
(b) tail
(c) cat -n
(d) None of the above
Ans: (a)
Explanation: The head command displays the top part of a document. We can choose to display n number of lines using the -n option followed by the number of lines we want to show.
52. Which command is used to change the password in Linux?
(a) passwd Alice
(b) passwd
(c) su -i
(d) passwd -g group_1
Ans: (b)
Explanation: Any user in Linux can change a password using the paswd command. Option (a) is whereby an admin uses option (c) to switch user accounts and then executes (a) to change the password for Alice. Option (d) is used to change a password for a group, that is why we have used option -g followed by the name of the group.
53. Among the following which is used to Decompress a file in Linux?
(a) gunzip
(b) zip
(c) gzip
(d) tar
Ans: (a)
Explanation: The gunzip command is used to decompress .gz compressed files in Linux. Other software used for compression and decompression include; zip, gzip, bzip2, compress, zcat to compress and bzcat, unzip, uncompress, gunzip to decompress. We can also use gzexe to compress executables. zmore to view compressed files, zcmp to compare compressed files, bzmore to view bzip compressed files, znew to recompress .z compressed files among others.
54. Which command do we use when we want to read the documentation of a command in Linux?
(a) man
(b) cat
(c) --help
(d) -h
Ans: (a)
Explanation: The Linux manual pages are used when we want to read up on the documentation of a command. We can use cmd --help / -h to list command options without moving away from the interactive terminal.
55. What command can we use to delete all files ending in .txt?
(a) rm *.txt
(b) rm .txt
(c) rm -rf .txt
(d) None of the above
Ans: (a)
Explanation: To delete all files ending in .txt we use command a that uses the * wildcard to match all files ending in .txt.
56. Which character is used to chain commands together in Linux?
(a) '
(b) ;
(c) :
(d) &&
Ans: (b), (d)
Explanation: To chain multiple commands in Linux, we can either separate the commands with ';' or '&&', For example, to create a new directory followed by files inside the directory we can chain four commands as follows;
$ cd ~/Documents; mkdir DIR_1; cd DIR_1; touch file{1..3}.txt;
# OR
$ cd ~/Documents && mkdir DIR_1 && cd DIR_1 && touch file{1..3}.txt;
This is also what we would do in a shell script to perform the actions.
57. Which command is used as a stream editor in Linux?
(a) sed
(b) awk
(c) grep
(d) egrep
Ans: (a)
Explanation: Sed is used for filtering streams in Linux. Other text filtering commands include Grep, Egrep, Fgrep, Rgrep, head, tail, sort, uniq, fmt, tr, awk among others.
58. What command can we use to search for 'Linux' in file.txt?
(a) grep "linux" file.txt
(b) grep -s "Linux" file.txt
(c) grep "Linux" file.txt
(d) None of the above
Ans: (c)
Explanation: In command (c), grep searches for the pattern 'Linux' in file.txt.
59. Which command do we use to locate repeated and non-repeated lines in Linux?
(a) cp
(b) uniq
(c) pr
(d) sort -u
Ans: (b), (d)
Explanation: The uniq and sort -u commands can be used to find and eliminate duplicates in Linux. cp command is used to copy files and directories in Linux. pr prepares a file for printing. The sort command is used for sorting in Linux.
60. What command is used to find a file in Linux?
(a) find
(b) locate
(c) search
(d) grep
Ans: (a) Explanation: The find command is similar to the search bar in windows OS. The find command recursively examines a directory tree looking for a matching file. In the case we have a filename, we can use the locate command. Grep looks for matches in a text file or command output.
Subscribe to my newsletter
Read articles from lumunge directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by