These Bash multiple-choice questions and their answers will help you strengthen your grip on the subject of Bash. You can prepare for an upcoming exam or job interview with these 50+ Bash MCQs.
So scroll down and start answering.
A. ( command )
B. Sh command
C. { command; }
D. (( command ))
A. 6
B. 123
C. 3
D. 600
A. The names of files that do not match finance.db
B. Information sent to the standard error-for example, errors that the find command displays as it runs
C. The names of files that match finance.db
D. Information sent to the standard output-that is, the path to files the find command has located
A. Sed -i '/^$/d' textfile
B. Sed '/^$/d' textfile
C. Cat textfile | sed '/^$/d
D. Sed -i 's/^$//' textfile
A. It would show the username, UID, and home directory of user1 separated by colons.
B. It would print the UID, GID, and home directory of user1 separated by hyphens.
C. It would print the UID, comment, and home directory of user1 separated by hyphens.
D. It would show the username, UID, and home directory of user1 separated by hyphens.
A. It will cause Bash to exit if a function or subshell returns a nonzero status code.
B. It will cause Bash to exit if a conditional returns a non-zero status code.
C. It will cause Bash to exit if local, declare, or typeset assignments return a nonzero status code.
D. It will cause Bash to exit if a command, list of commands, compound command, or potentially a pipeline returns a nonzero status code.
A. Get
B. Argument
C. Read
D. Input
A. A copy of the contents of file.sql
B. An error indicating that this is invalid syntax
C. The error output of the MySQL command
D. The non-error output of the MySQL command
A. When the command creates files, they will be owned by the group owner of the command.
B. The SUID bit allows anyone to execute the command no matter what other permissions are set.
C. When the command is executed, its running privileges elevate to the user owner of the command.
D. When the command is executed, its running privileges elevate to the group owner of the command.
A. Cat {$1,textfile}
B. Cat textfile | awk [print $1]
C. Cat textfile | awk '{print $1}'
D. Awk textfile {print $1}
A. Esc + R
B. Ctrl + H
C. Ctrl + R
D. Alt + R
A. Var=$( expr 10 / 8 )
B. (( var= 10 /8 ))
C. Var=$(( 10 / 8 ))
D. Var=$(echo 'scale=2; 10 / 8' | bc)
A. 0, representing 'true', because the variable
B. 0, representing 'true', because everybody loves penguins!
C. 1, representing 'false', because the variable "txt" is longer than eight characters
D. 1, representing 'false', because the variable "txt" does not contain eight lowercase letters between a and z
A. SHELL="HAL\>"
B. SHELL="HAL>"
C. export PS1="HAL>"
D. PS1="HAL\>"
A. /website.com/html/
B. /html/website.com/html/
C. /var/www/html/website.com/
D. Nothing will be echoed on the screen.
A. Ctrl + A (Windows) or Command + A (Mac)
B. Ctrl + E (Windows) or Command + E (Mac)
C. Ctrl + D (Windows) or Command + D (Mac)
D. Ctrl + Z (Windows) or Command + Z (Mac)
A. #!/usr/bin/env bash
B. ~/usr/bin/env bash
C. '$!/usr/bin/env bash
D. #/usr/bin/env bash
A. echo "The date is: !"
B. echo "The date is: date!"
C. echo "The date is: (date)!"
D. echo "The date is: $(date)!"
A. B, C, E
B. A, B, C
C. C, D, E
D. B, D, E
A. Find . -type html
B. Find . -name *.html
C. Find *.html
D. Find . -name \*.html -print
A. The output from the command line. By default STDIN comes from the keyboard.
B. Nothing because you can't redirect from file (in.txt) to another file (out.txt). You can only redirect from a command to a file.
C. It would be the contents of in.txt.
D. Nothing. The redirect will create a new empty file but there will not be any output from the cat command to redirect.
A. It loops between the values of $a and $b.
B. It tests whether the values of variables $a and $b are equal.
C. It returns $b if it is larger than $a.
D. It returns $a if it is larger than $b.
A. ; ;
B. : :
C. Done
D. $$
A. Touch file{1+10}.txt
B. Touch file{1-10}.txt
C. Touch file{1..10}.txt
D. Touch file(1..10).txt
A. $$
B. $?
C. $!
D. $@
A. It just works by default.
B. History --shared
C. History --combined
D. Shopt -s histappend
A. $@ treats each quoted argument as a separate entity. $* treats the entire argument string as one entity.
B. $* treats each quoted argument as a separate entity. $@ treats the entire argument string as one entity.
C. $* is used to count the arguments passed to a script, $@ provides all arguments in one string.
D. $* is the wildcard that includes all arguments with word splitting, $@ holds the same data but in an array.
A. /etc/bash.conf
B. ~/.profile
C. /etc/bashprofile
D. ~/profile
A. Nothing, this is an invalid file glob.
B. Hello.vertical-line.World
C. Hello[[.vertical-line.]]World
D. Hello|World
A. No such file
B. Ls: cannot access nonexistentfile: No such file or directory
C. Nothing, out.txt will be empty.
D. It will be the contents of nonexistentfile.
A. The output on the screen will be identical to out.txt
B. There will be no output on the screen as it's being redirected to out.txt.
C. The output on the screen will be identical to out.txt plus line numbers.
D. The out.txt file will hold STDERR and STDOUT will go to the screen.
A. History | find cp
B. History | grep cp
C. Grep cp history
D. Cp history
A. Bash for i in $(ls); do ... done
B. Bash for $(ls); do ... done
C. Bash for i in $ls; do ... done
D. Bash for $ls; do ... done
A. |
B. ->
C. #
D. @
A. (( \$num -gt 5 ))
B. [[$num -lt 5]]
C. (( \$num > 5 ))
D. \$num > 5
A. $0
B. $# // number of positional parameters
C. $$ // pid of the current shell
D. $@ // array-like construct of all positional parameters
A. There is an SELinux security context
B. The sticky bit is set and the file will stay in RAM for speed
C. There is an access control list
D. There is an extended attribute such as immutable set
A. It moves you to the directory you were previously in.
B. It moves you to your home folder (whatever your current working directory happens to be).
C. It deletes the current directory
D. It moves you one directory above your current working directory.
A. Accepts text from standard input and places it in "notes"
B. Creates "notes" and exits
C. Outputs the content of notes and deletes it
D. Appends text to the existing "notes"
A. This old rolling came rolling
B. This old man came man
C. This old man came rolling
D. This old came
A. $INCLUDE
B. $PATH
C. $PROGRAM
D. $PATHS
A. It creates an empty file called
B. It accepts text from the standard input and places it in the
C. It appends text to an existing file called
D. It outputs the contents of the
A. This old man came man
B. This old man came rolling
C. This old rolling came rolling
D. This old came
A. echo "Shall we play a game? yes/\no"
B. echo "Shall we play a game\? yes\\no"
C. echo "Shall we play a game? yes\\no"
D. echo "Shall we play a game? yes\no"
A. SELinux policy rules are checked after DAC rules.
B. SELinux policy rules are checked before DAC rules
C. SELinux policy rules are never checked after DAC rules.
D. None of these
A. It doesn't display information about the users currently on the machine.
B. It displays information about the users currently on the machine.
C. It displays information about the users currently on the another machine.
D. None of these
A. S/(.*)variable(.*variable)/\1rock\2/'
B. S/variable/rock/'
C. S/variable/rock/g'
D. S/(.*)variable(.*variable)/\1rock\2/'
A. Exec script.sh
B. Chmod +x script.sh
C. Bash script.sh
D. Source script.sh
A. Screen
B. Screen -X
C. Screen --shared
D. Terminal -shared
A. Ls < filelist.txt
B. Ls ¦ filelist.txt
C. Ls > filelist.txt
D. Ls - filelist.txt