Top Linux Multiple Choice Questions(MCQ) 2024

Explore the top Linux Multiple Choice Questions (MCQ) for 2024. Test your skills and stay ahead in the world of open-source technology.

  1. What is the default shell in Linux?

a) Bash

b) Korn

c) C Shell

d) Z Shell

Answer: a) Bash

  1. Which command is used to comment multiple lines in a Bash script?

a) /* comment */

b) // comment

c) # comment

d) <!– comment –>

Answer: c) # comment

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

  1. Question: Which symbol is used to represent the “not equal to” comparison in shell scripting?

a) ==

b) !=

c) <>

d) ><

Answer: b) !=

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

  1. 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”

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

  1. Which command is used to accept user input in a shell script?

a) input

b) read

c) get

d) accept

Answer: b) read

  1. How can command output be redirected to a file in shell scripting?

a) >

b) >>

c) |

d) &>

Answer: a) >

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

  1. Which symbol is used for command substitution in shell scripting?

a) {}

b) ()

c) <>

d) “

Answer: d) “ (backticks)

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

  1. Which command is used to delete a file in a shell script?

a) rm

b) delete

c) erase

d) del

Answer: a) rm

  1. 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() { }

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

  1. How can command-line arguments be accessed in a shell script?

a) $arg

b) $*

c) $arguments

d) $1, $2, …

Answer: d) $1, $2, …

  1. Which command is used to concatenate files in a shell script?

a) concat

b) merge

c) cat

d) append

Answer: c) cat

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

  1. How can comments spanning multiple lines be written in a shell script?

a) /* comment */

b) <!– comment –>

c) # comment

d) : ‘

comment

Answer: d) : ‘ … ‘

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

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

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

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

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

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

  1. 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)

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

  1. Which symbol is used for string concatenation in shell scripting?

a) &

b) +

c) .

d) %

Answer: c) .

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

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

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

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

  1. In a shell script, how is command substitution achieved?

a) {}

b) ()

c) {}

d) “

Answer: d) “ (backticks)

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

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

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

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

  1. How can comments be written within a single line in a shell script?

a) /* comment */

b) <!– comment –>

c) # comment

d) : ‘ … ‘

Answer: c) # comment

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

Enquire Now

Enquire Now

Enquire Now

Please Sign Up to Download

Please Sign Up to Download

Enquire Now

Please Sign Up to Download

Enquiry Form