0% found this document useful (0 votes)
8 views

60 mcqs Shell script and OS

The document contains a series of questions and answers related to shell commands and scripting in Linux. Key topics include the purpose of various commands, file management, process control, and shell variables. It also covers the default shell in Linux and macOS, as well as command syntax and usage.

Uploaded by

its2002sara
Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views

60 mcqs Shell script and OS

The document contains a series of questions and answers related to shell commands and scripting in Linux. Key topics include the purpose of various commands, file management, process control, and shell variables. It also covers the default shell in Linux and macOS, as well as command syntax and usage.

Uploaded by

its2002sara
Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 8

What is the primary purpose of a shell in an operating system?

A. Managing hardware resources


B. Interpreting user commands
C. Compiling programs
D. Running background services
ANSWER: B

Which of the following is NOT a shell in Linux?


A. Bash
B. Zsh
C. Korn
D. PyShell
ANSWER: D

What is the default shell in most Linux distributions?


A. Zsh
B. Bash
C. Fish
D. Korn
ANSWER: B

Which command is used to display the current directory in Linux?


A. ls
B. pwd
C. cd
D. dirname
ANSWER: B

What does the chmod command do?


A. Changes file ownership
B. Changes file permissions
C. Creates new directories
D. Displays file contents
ANSWER: B

Which symbol is used to redirect output to a file in shell scripting?


A. &
B. >
C. |
D. %
ANSWER: B

What is the purpose of the shebang (#!) in a shell script?


A. To specify the shell interpreter
B. To comment on the script
C. To indicate the script's filename
D. To add metadata to the script
ANSWER: A

Which command is used to display the first 10 lines of a file?


A. tail
B. head
C. cat
D. less
ANSWER: B

What does the grep command do?


A. Deletes files
B. Searches for patterns in files
C. Compresses files
D. Displays file permissions
ANSWER: B

Which symbol is used to run a command in the background?


A. &
B. >
C. |
D. *
ANSWER: A

What is the file descriptor for standard input (stdin)?


A. 0
B. 1
C. 2
D. 3
ANSWER: A

Which command is used to change the ownership of a file?


A. chown
B. chmod
C. mv
D. cp
ANSWER: A

What is the purpose of the awk command?


A. File copying
B. Text processing
C. File deletion
D. Script execution
ANSWER: B

Which command is used to terminate a running process by its PID?


A. kill
B. ps
C. stop
D. exit
ANSWER: A

What does the df command display?


A. File permissions
B. Disk space usage
C. Memory usage
D. CPU usage
ANSWER: B

Which operator is used for piping commands in shell scripting?


A. |
B. >
C. >>
D. &
ANSWER: A

What is the purpose of the echo command?


A. To execute scripts
B. To display messages or variables
C. To modify files
D. To list files
ANSWER: B
What does the uname command do?
A. Displays system information
B. Lists directory contents
C. Displays user accounts
D. Changes file permissions
ANSWER: A

Which of the following is NOT a type of shell variable?


A. Environment variable
B. Local variable
C. Session variable
D. Special variable
ANSWER: C

What is the exit status of a successful command in Linux?


A. 0
B. 1
C. -1
D. 255
ANSWER: A

Which command is used to compare two files?


A. cmp
B. diff
C. both A and B
D. none of the above
ANSWER: C

Which command is used to create a new directory?


A. mkdir
B. touch
C. cd
D. rm
ANSWER: A

What does the $? variable store in a shell script?


A. Current directory
B. Exit status of the last command
C. Process ID
D. Script name
ANSWER: B

Which command is used to display running processes?


A. ls
B. ps
C. kill
D. bg
ANSWER: B

What does the rm -r command do?


A. Deletes a single file
B. Deletes a directory and its contents recursively
C. Deletes a file permanently
D. Removes read permissions
ANSWER: B

Which of the following is a special character in shell scripting?


A. #
B. $
C. *
D. All of the above
ANSWER: D

What does the top command display?


A. Memory usage
B. CPU usage
C. Running processes
D. All of the above
ANSWER: D

What is the purpose of the alias command?


A. To delete files
B. To create shortcuts for commands
C. To view hidden files
D. To terminate processes
ANSWER: B

Which symbol is used for comments in shell scripts?


A. //
B. #
C. /* */
D. ;
ANSWER: B

What is the default file descriptor for standard error (stderr)?


A. 0
B. 1
C. 2
D. 3
ANSWER: C

Which command appends text to a file?


A. >
B. >>
C. <
D. |
ANSWER: B

What is the purpose of the cut command?


A. Copying files
B. Splitting files
C. Extracting fields from text
D. Sorting files
ANSWER: C

Which symbol is used to concatenate strings in shell scripting?


A. +
B. .
C. ,
D. None (just place strings adjacent to each other)
ANSWER: D

What is the output of ls | wc -l?


A. Total word count of the files in the directory
B. Number of files in the directory
C. Number of lines in all files
D. Total size of files in bytes
ANSWER: B

Which command is used to schedule tasks in Linux?


A. cron
B. schedule
C. bg
D. top
ANSWER: A
What is the purpose of the touch command in Linux?
A. To create a new file
B. To modify file contents
C. To change file permissions
D. To display file details
ANSWER: A

Which command is used to display the content of a file one screen at a time?
A. more
B. less
C. cat
D. both A and B
ANSWER: D

What does the export command do in shell scripting?


A. Exports files to another directory
B. Sets environment variables
C. Deletes environment variables
D. Copies files
ANSWER: B

Which command is used to delete empty directories?


A. rm
B. rmdir
C. del
D. erase
ANSWER: B

What is the purpose of the wc command?


A. Count words, lines, and characters in a file
B. Display file permissions
C. List files in a directory
D. Compress files
ANSWER: A

Which of the following is a valid loop structure in shell scripting?


A. for
B. while
C. until
D. All of the above
ANSWER: D

Which command is used to search for files in Linux?


A. find
B. locate
C. both A and B
D. search
ANSWER: C

What is the purpose of the basename command?


A. Display the directory name of a file path
B. Display the file name from a file path
C. Both A and B
D. None of the above
ANSWER: B

Which of the following operators is used for string comparison in shell scripting?
A. -eq
B. ==
C. -lt
D. !=
ANSWER: B

What does the trap command do in a shell script?


A. Handles signals and interrupts
B. Terminates running processes
C. Debugs the script
D. Displays an error message
ANSWER: A

What is the purpose of the df -h command?


A. Displays human-readable disk space usage
B. Lists hidden files
C. Displays file hierarchy
D. Compresses files
ANSWER: A

Which command is used to print the current user’s username?


A. who
B. whoami
C. uname
D. id
ANSWER: B

Which of the following is NOT a valid file test operator in shell scripting?
A. -f
B. -d
C. -e
D. -x
ANSWER: D

What does the sed command do?


A. Stream editing and pattern matching
B. Sorts files in a directory
C. Searches for files
D. Deletes files
ANSWER: A

Which command is used to view the kernel version?


A. uname -r
B. version -k
C. osinfo
D. kerninfo
ANSWER: A

What is the default shell in macOS?


A. Bash
B. Zsh
C. Korn Shell
D. C Shell
ANSWER: B

Which command is used to concatenate files in Linux?


A. combine
B. join
C. cat
D. merge
ANSWER: C

What does the fg command do in Linux?


A. Brings a background job to the foreground
B. Kills a background process
C. Displays file groups
D. Switches between user sessions
ANSWER: A

Which of the following is NOT a shell scripting conditional statement?


A. if
B. case
C. loop
D. elif
ANSWER: C

What is the purpose of the uptime command?


A. Displays the system boot time
B. Shows how long the system has been running
C. Checks the system's response time
D. Displays time and date
ANSWER: B

Which command is used to sort lines in a file?


A. arrange
B. order
C. sort
D. organize
ANSWER: C

What does the history command do?


A. Displays the last modified date of a file
B. Shows recently used commands
C. Lists the system's uptime history
D. Tracks file changes
ANSWER: B

Which of the following is NOT an operating system?


A. Linux
B. Windows
C. Git
D. macOS
ANSWER: C

Which command is used to compress files in Linux?


A. gzip
B. tar
C. zip
D. All of the above
ANSWER: D

What does the killall command do?


A. Kills all processes
B. Kills processes by name
C. Terminates user sessions
D. Restarts the system
ANSWER: B

You might also like