Explore the top Linux Multiple Choice Questions (MCQ) for 2024. Test your skills and stay ahead in the world of open-source technology.
- What is the default shell in Linux?
a) Bash
b) Korn
c) C Shell
d) Z Shell
Answer: a) Bash
- Which command is used to comment multiple lines in a Bash script?
a) /* comment */
b) // comment
c) # comment
d) <!– comment –>
Answer: c) # comment
- In shell scripting, what does the ‘if’ statement do?
a) Checks the existence of a file
b) Performs arithmetic operations
c) Executes commands based on conditions
d) Prints text to the console
Answer: c) Executes commands based on conditions
- Question: Which symbol is used to represent the “not equal to” comparison in shell scripting?
a) ==
b) !=
c) <>
d) ><
Answer: b) !=
- What does the ‘echo’ command do in a shell script?
a) Prints the contents of a file
b) Executes a command
c) Displays output to the terminal
d) Copies files
Answer: c) Displays output to the terminal
- How can a variable be assigned in a Bash script?
a) variable = value
b) variable := value
c) variable = “value”
d) variable=”value”
Answer: d) variable=”value”
- What is the purpose of the ‘for’ loop in shell scripting?
a) Repeats a command indefinitely
b) Executes commands based on conditions
c) Iterates through a list of items
d) Checks file permissions
Answer: c) Iterates through a list of items
- Which command is used to accept user input in a shell script?
a) input
b) read
c) get
d) accept
Answer: b) read
- How can command output be redirected to a file in shell scripting?
a) >
b) >>
c) |
d) &>
Answer: a) >
- What does the ‘exit’ command do in a shell script?
a) Closes the terminal
b) Exits the current loop
c) Terminates the script execution
d) Restarts the system
Answer: c) Terminates the script execution
- Which symbol is used for command substitution in shell scripting?
a) {}
b) ()
c) <>
d) “
Answer: d) “ (backticks)
- What does the ‘case’ statement do in a shell script?
a) Defines constants
b) Executes commands based on conditions
c) Performs arithmetic operations
d) Checks file permissions
Answer: b) Executes commands based on conditions
- Which command is used to delete a file in a shell script?
a) rm
b) delete
c) erase
d) del
Answer: a) rm
- In a shell script, how is a function defined?
a) function_name() { }
b) define function_name()
c) function function_name { }
d) func function_name() { }
Answer: a) function_name() { }
- What does the ‘sleep’ command do in a shell script?
a) Shuts down the system
b) Pauses the script execution for a specified duration
c) Displays system uptime
d) Checks network connectivity
Answer: b) Pauses the script execution for a specified duration
- How can command-line arguments be accessed in a shell script?
a) $arg
b) $*
c) $arguments
d) $1, $2, …
Answer: d) $1, $2, …
- Which command is used to concatenate files in a shell script?
a) concat
b) merge
c) cat
d) append
Answer: c) cat
- What does the ‘export’ command do in a shell script?
a) Deletes a variable
b) Sets a variable value
c) Imports environment variables
d) Makes a variable available to child processes
Answer: d) Makes a variable available to child processes
- How can comments spanning multiple lines be written in a shell script?
a) /* comment */
b) <!– comment –>
c) # comment
d) : ‘
comment
‘
Answer: d) : ‘ … ‘
- What is the purpose of the ‘continue’ statement in a shell script?
a) Terminates the script
b) Skips the current iteration in a loop
c) Moves to the next line
d) Restarts the script execution
Answer: b) Skips the current iteration in a loop
- Which command is used to check the existence of a directory in a shell script?
a) test -f
b) check -d
c) [ -d ]
d) test -d
Answer: d) test -d
- What is the purpose of the ‘grep’ command in shell scripting?
a) Search for text patterns in files
b) Display disk usage
c) Print the current date and time
d) Group multiple commands
Answer: a) Search for text patterns in files
- How can a shell script be made executable?
a) chmod +x script.sh
b) execute script.sh
c) run script.sh
d) permit script.sh
Answer: a) chmod +x script.sh
- Which command is used to read a file line by line in a shell script?
a) read
b) readfile
c) cat
d) open
Answer: a) read
- What does the ‘cut’ command do in shell scripting?
a) Cut the first part of a file
b) Split files into smaller parts
c) Extract specific columns from a file
d) Remove content from a file
Answer: c) Extract specific columns from a file
- In a shell script, how is the output of a command stored into a variable?
a) variable = command
b) variable := command
c) variable=$(command)
d) variable-command
Answer: c) variable=$(command)
- What does the ‘shift’ command do in a shell script?
a) Moves a file from one directory to another
b) Shifts command-line arguments
c) Deletes a variable
d) Exits the script
Answer: b) Shifts command-line arguments
- Which symbol is used for string concatenation in shell scripting?
a) &
b) +
c) .
d) %
Answer: c) .
- What does the ‘basename’ command do in shell scripting?
a) Prints the working directory
b) Displays the base name of a file path
c) Deletes a file
d) Extracts file permissions
Answer: b) Displays the base name of a file path
- What is the purpose of the ‘trap’ command in shell scripting?
a) Terminate the script
b) Capture signals and perform specified actions
c) Display a message
d) Trigger an error
Answer: b) Capture signals and perform specified actions
- Which command is used to create a symbolic link in a shell script?
a) ln -s
b) symlink
c) mklink
d) link
Answer: a) ln -s
- What does the ‘expr’ command do in shell scripting?
a) Evaluate expressions
b) Export variables
c) Execute a script
d) Expand variables
Answer: a) Evaluate expressions
- In a shell script, how is command substitution achieved?
a) {}
b) ()
c) {}
d) “
Answer: d) “ (backticks)
- What does the ‘tee’ command do in shell scripting?
a) Combine multiple files
b) Display file contents
c) Redirect output to multiple files and terminal
d) Merge file contents
Answer: c) Redirect output to multiple files and terminal
- How can a shell script accept command-line arguments?
a) Using the $arguments variable
b) Using input()
c) By declaring parameters
d) By using the -args flag
Answer: c) By declaring parameters
- Which command is used to check the length of a string in a shell script?
a) len
b) strlen
c) strlength
d) length
Answer: b) strlen
- What does the ‘dirname’ command do in shell scripting?
a) Display the current directory
b) Print the directory path of a file
c) Delete a directory
d) Show file permissions
Answer: b) Print the directory path of a file
- How can comments be written within a single line in a shell script?
a) /* comment */
b) <!– comment –>
c) # comment
d) : ‘ … ‘
Answer: c) # comment
- Question:
What does the ‘read -p’ command do in shell scripting?
a) Reads user input with a specified prompt
b) Reads the content of a file
c) Reads environment variables
d) Reads a file permission
Answer: a) Reads user input with a specified prompt