ads

MCQs based on shell scripting

 Multiple-choice questions (MCQs) based on shell scripting along with their answers:





1. What is the primary purpose of shell scripting?

   a) To write complex graphical user interfaces

   b) To automate repetitive tasks in a Unix-like operating system

   c) To develop web applications

   d) To create system drivers

   Answer: b


2. Which shell is commonly used for shell scripting on Unix-like systems?

   a) C shell (csh)

   b) Bourne shell (sh)

   c) PowerShell

   d) Fish shell

   Answer: b


3. Which command is used to create a new shell script file?

   a) touch

   b) new

   c) create

   d) nano

   Answer: a


4. Which character is used to denote comments in shell scripting?

   a) //

   b) --

   c) #

   d) %%

   Answer: c


5. What is the file extension commonly used for shell script files?

   a) .txt

   b) .sh

   c) .script

   d) .bash

   Answer: b


6. Which command is used to execute a shell script?

   a) run

   b) execute

   c) sh

   d) bash

   Answer: c


7. What is the purpose of the shebang (#!) at the beginning of a shell script?

   a) It comments out the script

   b) It specifies the shell to interpret the script

   c) It indicates the end of the script

   d) It marks the beginning of a function

   Answer: b


8. Which command is used to display the output of a shell script?

   a) display

   b) print

   c) echo

   d) show

   Answer: c


9. What is the purpose of the exit command in a shell script?

   a) To terminate the shell itself

   b) To exit from a loop

   c) To exit from the script with a specified exit status

   d) To clear the terminal screen

   Answer: c


10. Which command is used to define a variable in a shell script?

    a) set

    b) define

    c) var

    d) export

    Answer: a


11. What is the purpose of the $? variable in shell scripting?

    a) It stores the process ID of the last executed command

    b) It stores the exit status of the last executed command

    c) It stores the output of the last executed command

    d) It represents the current user's home directory

    Answer: b


12. Which command is used to read input from the user in a shell script?

    a) read

    b) input

    c) get

    d) scanf

    Answer: a


13. What does the following command do in shell scripting? `chmod +x script.sh`

    a) Changes the file extension of the script

    b) Makes the script executable

    c) Deletes the script

    d) Copies the script

    Answer: b


14. Which command is used to concatenate strings in a shell script?

    a) concat

    b) join

    c) +

    d) .

    Answer: d


15. What does the following conditional statement do in shell scripting?

    

shell

    if [ -f "file.txt" ]; then

        echo "File exists"

    else

        echo "File does not exist"

    fi

    a) Checks if a file named "file.txt" exists

    b) Checks if a directory named "file.txt" exists

    c) Checks if "file.txt" is a regular file

    d) Checks if "file.txt" is executable

    Answer: c


16. Which command is used to perform integer comparison in a shell script?

    a) cmp

    b) compare

    c) test

    d) [ ]

    Answer: d


17. What is the purpose of the `case` statement in shell scripting?

    a) To execute a block of code repeatedly

    b) To create a loop

    c) To perform multiple conditional checks

    d) To define a function

    Answer: c


18. Which command is used to create a loop in shell scripting?

    a) for

    b) loop

    c) repeat

    d) while

    Answer: a


19. What is the purpose of the `break` statement in a shell script loop?

    a) To skip the current iteration and move to the next one

    b) To exit the loop immediately

    c) To restart the loop from the beginning

    d) To increase the loop counter

    Answer: b


20. Which command is used to redirect the output of a command to a file in shell scripting?

    a) >

    b) >>

    c) <

    d) <<

    Answer: a


21. What does the `&&` operator do in shell scripting?

    a) Performs logical OR operation

    b) Performs logical AND operation

    c) Performs bitwise AND operation

    d) Concatenates strings

    Answer: b


22. What does the `||` operator do in shell scripting?

    a) Performs logical OR operation

    b) Performs logical AND operation

    c) Performs bitwise OR operation

    d) Concatenates strings

    Answer: a


23. Which command is used to list the files in a directory in shell scripting?

    a) list

    b) dir

    c) ls

    d) show

    Answer: c


24. What is the purpose of the `export` command in shell scripting?

    a) To import variables from another script

    b) To define a global variable

    c) To export variables to the environment

    d) To execute a script

    Answer: c


25. Which command is used to delete a file in shell scripting?

    a) rm

    b) del

    c) erase

    d) remove

    Answer: a


26. What does the `grep` command do in shell scripting?

    a) Searches for patterns in files

    b) Deletes files

    c) Copies files

    d) Moves files

    Answer: a


27. Which command is used to find and replace text in files in shell scripting?

    a) replace

    b) subst

    c) sed

    d) swap

    Answer: c


28. What does the `cut` command do in shell scripting?

    a) Cuts text from files

    b) Copies files

    c) Moves files

    d) Deletes files

    Answer: a


29. Which command is used to sort lines of text files in shell scripting?

    a) order

    b) sort

    c) arrange

    d) organize

    Answer: b


30. What does the `awk` command do in shell scripting?

    a) Filters and processes text

    b) Deletes files

    c) Moves files

    d) Copies files

    Answer: a


31. Which command is used to count lines, words, and characters in files in shell scripting?



    a) count

    b) wc

    c) tally

    d) sum

    Answer: b


32. What is the purpose of the `tar` command in shell scripting?

    a) To compress files

    b) To create archives

    c) To encrypt files

    d) To decrypt files

    Answer: b


33. Which command is used to compress files in shell scripting?

    a) zip

    b) gzip

    c) compress

    d) tar

    Answer: b


34. What does the `dirname` command do in shell scripting?

    a) Returns the directory part of a pathname

    b) Returns the filename part of a pathname

    c) Returns the current directory

    d) Creates a new directory

    Answer: a


35. Which command is used to create a symbolic link in shell scripting?

    a) link

    b) symlink

    c) ln

    d) point

    Answer: c


36. What does the `find` command do in shell scripting?

    a) Searches for files and directories

    b) Deletes files

    c) Moves files

    d) Copies files

    Answer: a


37. Which command is used to display the manual pages for commands in shell scripting?

    a) man

    b) help

    c) info

    d) doc

    Answer: a


38. What is the purpose of the `tee` command in shell scripting?

    a) To copy standard input to standard output

    b) To redirect output to a file

    c) To display the contents of a file

    d) To append to a file

    Answer: b


39. Which command is used to set the permissions of files and directories in shell scripting?

    a) chmod

    b) setperm

    c) perm

    d) rights

    Answer: a


40. What is the purpose of the `cron` command in shell scripting?

    a) To schedule recurring tasks

    b) To create new users

    c) To list processes

    d) To monitor system logs

    Answer: a


41. Which command is used to list environment variables in shell scripting?

    a) env

    b) vars

    c) listenv

    d) showenv

    Answer: a


42. What is the purpose of the `export` command in shell scripting?

    a) To import variables from another script

    b) To define a global variable

    c) To export variables to the environment

    d) To execute a script

    Answer: c


43. Which command is used to concatenate files in shell scripting?

    a) cat

    b) concat

    c) merge

    d) join

    Answer: a


44. What is the purpose of the `expr` command in shell scripting?

    a) To evaluate mathematical expressions

    b) To print the value of a variable

    c) To list files and directories

    d) To create symbolic links

    Answer: a


45. Which command is used to perform arithmetic operations in shell scripting?

    a) calc

    b) math

    c) expr

    d) add

    Answer: c


46. What is the purpose of the `ifconfig` command in shell scripting?

    a) To configure network interfaces

    b) To list active network connections

    c) To display system information

    d) To check disk space

    Answer: a


47. Which command is used to display disk usage statistics in shell scripting?

    a) df

    b) disk

    c) du

    d) usage

    Answer: a


48. What does the `uname` command do in shell scripting?

    a) Returns the current username

    b) Returns the system's hostname

    c) Returns the system's kernel name

    d) Returns the system's IP address

    Answer: c


49. Which command is used to display the current date and time in shell scripting?

    a) now

    b) time

    c) date

    d) clock

    Answer: c


50. What is the purpose of the `kill` command in shell scripting?

    a) To terminate processes

    b) To list running processes

    c) To suspend processes

    d) To restart the system

    Answer: a


51. Which command is used to create a new directory in shell scripting?

    a) mkfile

    b) mkdir

    c) newdir

    d) touchdir

    Answer: b


52. What does the `pwd` command do in shell scripting?

    a) Prints the current user's password

    b) Prints the current working directory

    c) Prints the system's uptime

    d) Prints the contents of a file

    Answer: b


53. Which command is used to remove a directory in shell scripting?

    a) rmdir

    b) rm

    c) removedir

    d) del

    Answer: a


54. What is the purpose of the `uptime` command in shell scripting?

    a) To display the system's uptime

    b) To check the status of network interfaces

    c) To list active processes

    d) To monitor disk usage

    Answer: a


55. Which command is used to display the contents of a file in shell scripting?

    a) print

    b) cat

    c) show

    d) display

    Answer: b


56. What does the `history` command do in shell scripting?

    a) Displays the command history

    b) Lists the contents of the current directory

    c) Prints the current date and time

    d) Executes the last command

    Answer: a


57. Which command is used to move or rename files and directories in shell scripting?

    a) mv

    b) move

    c) rename

    d) cp

    Answer: a


58. What does the `whoami` command do in shell scripting?

    a) Displays the current user's ID

    b) Lists the currently logged-in users

    c) Prints the current username

    d) Shows the system's hostname

    Answer: c


59. Which command is used to display the manual page for a specific command in shell scripting?

    a) info

    b) help

    c) man

    d) manual

    Answer: c


60. What is the purpose of the `echo` command in shell scripting?

    a) To display the contents of a file

    b) To print text to the terminal

    c) To execute a command

    d) To redirect output to a file

    Answer: b


61. Which command is used to search for files in a directory hierarchy based on specific criteria in shell scripting?

    a) search

    b) grep

    c) locate

    d) find

    Answer: d


62. What does the `touch` command do in shell scripting?

    a) Deletes files

    b) Creates empty files or updates the timestamp of existing files

    c) Moves files

    d) Lists files

    Answer: b


63. Which command is used to display the contents of environment variables in shell scripting?

    a) env

    b) vars

    c) printenv

    d) showenv

    Answer: c


64. What is the purpose of the `cut` command in shell scripting?

    a) To copy files

    b) To remove files

    c) To extract specific columns or fields from files

    d) To move files

    Answer: c


65. Which command is used to display the last few lines of a file in shell scripting?

    a) last

    b) tail

    c) end

    d) bottom

    Answer: b


66. What is the purpose of the `sed` command in shell scripting?

    a) To perform pattern matching and text substitution

    b) To list files

    c) To compress files

    d) To encrypt files

    Answer: a


67. Which command is used to display the contents of compressed files in shell scripting?

    a) zip

    b) unzip

    c) gzip

    d) tar

    Answer: c


68. What does the `ln` command do in shell scripting?

    a) Lists files

    b) Moves files

    c) Creates links between files

    d) Deletes files

    Answer: c


69. Which command is used to display the size of files and directories in shell scripting?

    a) size

    b) stat

    c) ls

    d) du

    Answer: d


70. What does the `tee` command do in shell scripting?

    a) Prints text to the terminal

    b) Redirects output to a file and also prints it to the terminal

    c) Deletes files

    d) Moves files

    Answer: b



-- Code With VDK

Post a Comment

0 Comments
* Please Don't Spam Here. All the Comments are Reviewed by Admin.

#buttons=(Ok, Go it!) #days=(20)

Our website uses cookies to enhance your experience. Learn More
Ok, Go it!