Docsity

Cambridge Certified Unix Shell Scriptor Exam, Exams of Technology

Toggle sidebar
bg1
Cambridge Certified Unix Shell Scriptor Practice Exam
Q1: Which of the following best describes the role of the shell in a Unix system?
A) The system kernel
B) A command interpreter
C) A file management utility
D) A hardware driver
Answer: B
Explanation: The shell serves as the command interpreter that reads user commands and executes them
by communicating with the kernel.
Q2: What is the primary purpose of the shebang line (e.g., #!/bin/bash) in a Unix shell script?
A) To comment out the script
B) To indicate the file’s author
C) To specify which interpreter to use
D) To set environment variables
Answer: C
Explanation: The shebang line tells the system which interpreter (e.g., bash) should be used to execute
the script.
Q3: Which Unix component is primarily responsible for managing hardware resources?
A) The shell
B) The kernel
C) The file system
D) The user interface
Answer: B
Explanation: The kernel manages hardware resources and provides essential services for processes.
Q4: In Unix, what is meant by “interactive shell usage”?
A) Running scripts automatically at boot time
B) Entering commands one by one in real time
C) Scheduling tasks with cron
D) Managing background processes
Answer: B
Explanation: Interactive shell usage refers to manually entering and executing commands in real time.
Q5: Which of these is NOT a Unix shell type?
A) Bourne Shell (sh)
B) Bash (Bourne Again Shell)
C) KornShell (ksh)
D) Notepad Shell
Answer: D
Explanation: Notepad Shell is not a Unix shell; the others are common Unix shells.
Q6: What does the Unix shell prompt typically indicate?
A) The current user and directory
B) The list of available commands
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff
pf12
pf13
pf14
pf15
pf16
pf17
pf18
pf19
pf1a
pf1b
pf1c
pf1d
pf1e
pf1f
pf20
pf21
pf22
pf23
pf24
pf25
pf26
pf27
pf28
pf29
pf2a
pf2b
pf2c
pf2d

Partial preview of the text

Download Cambridge Certified Unix Shell Scriptor Exam and more Exams Technology in PDF only on Docsity!

Cambridge Certified Unix Shell Scriptor Practice Exam

Q1: Which of the following best describes the role of the shell in a Unix system? A) The system kernel B) A command interpreter C) A file management utility D) A hardware driver Answer: B Explanation: The shell serves as the command interpreter that reads user commands and executes them by communicating with the kernel. Q2: What is the primary purpose of the shebang line (e.g., #!/bin/bash) in a Unix shell script? A) To comment out the script B) To indicate the file’s author C) To specify which interpreter to use D) To set environment variables Answer: C Explanation: The shebang line tells the system which interpreter (e.g., bash) should be used to execute the script. Q3: Which Unix component is primarily responsible for managing hardware resources? A) The shell B) The kernel C) The file system D) The user interface Answer: B Explanation: The kernel manages hardware resources and provides essential services for processes. Q4: In Unix, what is meant by “interactive shell usage”? A) Running scripts automatically at boot time B) Entering commands one by one in real time C) Scheduling tasks with cron D) Managing background processes Answer: B Explanation: Interactive shell usage refers to manually entering and executing commands in real time. Q5: Which of these is NOT a Unix shell type? A) Bourne Shell (sh) B) Bash (Bourne Again Shell) C) KornShell (ksh) D) Notepad Shell Answer: D Explanation: Notepad Shell is not a Unix shell; the others are common Unix shells. Q6: What does the Unix shell prompt typically indicate? A) The current user and directory B) The list of available commands

C) The amount of free memory D) The system uptime Answer: A Explanation: The shell prompt usually shows the current user and working directory to provide context. Q7: Which command is used to change file permissions in Unix? A) chperm B) chmod C) chown D) chgrp Answer: B Explanation: The chmod command is used to change file permissions. Q8: What does “stdin” refer to in Unix? A) Standard output stream B) Standard error stream C) Standard input stream D) Standard data stream Answer: C Explanation: “stdin” stands for the standard input stream, which is where a program reads its input. Q9: How does the Unix file system hierarchy begin? A) With the /home directory B) With the root (/) directory C) With the /usr directory D) With the /bin directory Answer: B Explanation: The Unix file system starts at the root directory, denoted by “/”. Q10: Which command is used to list the contents of a directory in Unix? A) list B) show C) ls D) dirlist Answer: C Explanation: The ls command lists directory contents. Q11: In Unix, what is the purpose of file descriptors? A) To assign names to files B) To provide identifiers for input/output streams C) To compress files D) To encrypt files Answer: B Explanation: File descriptors are integer handles that represent open files or streams (stdin, stdout, stderr).

Answer: C Explanation: “chmod +x” makes the script executable. Q18: How does the Unix file system handle hidden files? A) Files starting with a period (.) are hidden B) Files in the /hidden directory are hidden C) Files with a .hid extension are hidden D) Files with no extension are hidden Answer: A Explanation: Files beginning with a dot (.) are treated as hidden in Unix. Q19: Which command is used to display the manual pages for Unix commands? A) help B) info C) man D) guide Answer: C Explanation: The man command displays the manual pages for Unix commands. Q20: What is the main advantage of using a shell script over manual command entry? A) It eliminates the need for a kernel B) It automates repetitive tasks C) It provides better hardware performance D) It hides the commands from the user Answer: B Explanation: Shell scripts allow automation of repetitive tasks, saving time and reducing errors. Q21: What is one key difference between Bash and the original Bourne Shell? A) Bash does not support variables B) Bash is only for system administrators C) Bash offers improved scripting features and interactivity D) Bash cannot run on Unix systems Answer: C Explanation: Bash (Bourne Again Shell) includes many enhancements over the original Bourne Shell, such as improved scripting capabilities and interactive features. Q22: Which statement accurately describes file permissions in Unix? A) File permissions are only set by the system administrator B) They determine who can read, write, or execute a file C) They are not applicable to shell scripts D) They are automatically set to full access for every file Answer: B Explanation: File permissions in Unix determine the level of access (read, write, execute) granted to users and groups. Q23: What is the first character you should use when writing a comment in a Unix shell script? A) /

B)

C) %

D) ;

Answer: B Explanation: The hash symbol (#) is used to indicate a comment in shell scripts. Q24: Which command would you use to print formatted text to the terminal? A) echo B) printf C) print D) format Answer: B Explanation: The printf command is used for printing formatted text in Unix. Q25: In shell scripting, which symbol is used to reference the value of a variable? A) @ B) $ C) & D) % Answer: B Explanation: The dollar sign ($) is used to reference the value stored in a variable. Q26: Which command is used to read user input in a shell script? A) input B) read C) get D) fetch Answer: B Explanation: The read command is used to accept user input in a shell script. Q27: How can you access the first command-line argument passed to a shell script? A) $ B) $ C) $ D) $@ Answer: B Explanation: $1 represents the first argument passed to the script (with $0 being the script name). Q28: Which control structure is used for executing code conditionally in shell scripts? A) loop B) if-else C) switch D) case Answer: B Explanation: The if-else structure is used for conditional execution in shell scripts.

Answer: B Explanation: Prepending “./” specifies the current directory when executing a script. Q35: What does the variable “$?” represent in Unix shell scripting? A) The script’s process ID B) The exit status of the last command C) The number of arguments passed D) The current user’s ID Answer: B Explanation: “$?” holds the exit status of the previously executed command. Q36: Which command is used to create a new empty file in Unix? A) new B) touch C) makefile D) create Answer: B Explanation: The touch command is used to create an empty file or update its timestamp. Q37: What does the “cp” command do in Unix? A) Copy files or directories B) Change file permissions C) Remove files D) Compare files Answer: A Explanation: The cp command is used to copy files or directories from one location to another. Q38: Which command is used to remove a directory that is empty in Unix? A) rm - r B) rmdir C) deldir D) removedir Answer: B Explanation: The rmdir command removes directories, but only if they are empty. Q39: Which Unix command is used to view the first few lines of a file? A) head B) tail C) cat D) less Answer: A Explanation: The head command displays the beginning lines of a file. Q40: How can you view the content of a file without modifying it in Unix? A) vi B) cat C) edit

D) more Answer: D Explanation: The more command lets you view the contents of a file page by page without editing. Q41: Which operator is used to redirect standard error to a file? A) 1> B) 2> C) &> D) > Answer: B Explanation: The “2>” operator redirects the standard error (file descriptor 2) to a file. Q42: What is the primary function of the “find” command in Unix? A) To locate files based on criteria B) To list directory contents C) To display file permissions D) To change file ownership Answer: A Explanation: The find command searches for files and directories based on specified criteria. Q43: Which command is commonly used for searching text within files using patterns? A) search B) locate C) grep D) findtext Answer: C Explanation: The grep command searches for text patterns within files. Q44: What does the “mv” command do? A) Moves or renames files and directories B) Copies files C) Views file contents D) Merges two files Answer: A Explanation: The mv command is used to move or rename files and directories. Q45: In Unix, which command is used to concatenate and display file contents? A) concat B) combine C) cat D) join Answer: C Explanation: The cat command reads and outputs the contents of files sequentially. Q46: What is the purpose of the “ln” command in Unix? A) To list files in long format B) To create hard or symbolic links

B) $@

C) $

D) $?

Answer: A Explanation: The variable $# contains the count of positional parameters passed to the script. Q53: In shell scripting, what does the “read” command do when used without options? A) It reads from a file B) It reads user input from stdin C) It displays file contents D) It executes a command Answer: B Explanation: The read command waits for user input from the standard input stream. Q54: Which operator can be used for command chaining where the next command runs only if the previous one succeeds? A) && B) || C) ; D) & Answer: A Explanation: The && operator ensures that the following command executes only if the preceding command returns a success status. Q55: What is the correct syntax to define a function in Bash? A) function myfunc() { commands; } B) def myfunc { commands; } C) myfunc() => { commands; } D) function: myfunc { commands; } Answer: A Explanation: In Bash, functions are defined using the syntax: function myfunc() { ... }. Q56: Which of the following best describes the “for” loop in shell scripting? A) It repeatedly executes commands until a condition becomes false B) It iterates over a sequence of words or numbers C) It waits for user input before each iteration D) It only works with numeric sequences Answer: B Explanation: The for loop iterates over a list of items, executing commands for each item in the sequence. Q57: What does the “while” loop do in a shell script? A) Executes commands only once B) Executes commands based on a fixed list C) Continues execution while a condition is true D) Iterates over files in a directory

Answer: C Explanation: A while loop executes its commands repeatedly as long as its condition evaluates to true. Q58: Which operator is used in shell scripts to compare strings for equality? A) - eq B) = C) == D) != Answer: B Explanation: In shell scripts, the single equal sign (=) is used within test brackets ([ ]) for string equality comparisons. Q59: What does the “expr” command primarily do in Unix shell scripting? A) Express text formatting B) Perform arithmetic and string operations C) Export environment variables D) Execute scripts in parallel Answer: B Explanation: The expr command is used for evaluating expressions and performing simple arithmetic or string operations. Q60: Which command is used to extract a substring from a variable in Bash? A) cut B) substr C) expr substr D) awk Answer: C Explanation: The expr command can be used with the substr option to extract parts of a string. Q61: What is the purpose of using regular expressions in shell scripting? A) To create new files B) To perform pattern matching and text manipulation C) To set file permissions D) To manage background processes Answer: B Explanation: Regular expressions are used to match patterns and transform text within scripts. Q62: Which Unix command can perform stream editing for automated text transformations? A) grep B) sed C) awk D) cut Answer: B Explanation: The sed command is a stream editor that can perform find-and-replace operations on text. Q63: Which tool is best suited for scanning and processing text based on patterns in Unix? A) sed

Explanation: The || operator allows execution of the next command only if the previous command returns a non-zero (failure) exit status. Q69: What is the purpose of the “trap” command in shell scripting? A) To secure files B) To catch and handle signals or errors C) To encrypt data D) To monitor system resources Answer: B Explanation: The trap command allows a script to intercept signals and errors to perform cleanup or error handling. Q70: Which flag would you use with Bash to exit a script immediately if a command fails? A) - e B) - x C) - v D) - n Answer: A Explanation: The - e flag makes the script exit immediately if any command returns a non-zero exit status. Q71: What does the “set - x” command do in a shell script? A) Disables command tracing B) Enables command tracing for debugging C) Exits the script on error D) Changes file permissions Answer: B Explanation: The “set - x” option prints each command and its arguments to the terminal before execution, aiding debugging. Q72: Which of the following is a method for reading files line by line in a shell script? A) for loop with file redirection B) while read loop C) if-else block D) case statement Answer: B Explanation: A while read loop is commonly used to process a file line by line. Q73: In shell scripting, how can you check if a variable is set? A) Using - n operator in test B) Using - z operator in test C) Using isset() function D) Using $? Answer: A Explanation: The - n operator tests if a variable is non-empty, indicating that it is set.

Q74: What is the purpose of using functions in shell scripts? A) To allocate memory B) To modularize code and avoid repetition C) To secure the script D) To manage background processes Answer: B Explanation: Functions help break down the script into reusable and maintainable sections. Q75: Which command would you use to list the groups that a user belongs to in Unix? A) groups B) id C) whoami D) passwd Answer: A Explanation: The groups command displays all groups associated with a user. Q76: How do you change the owner of a file in Unix? A) chperm B) chgrp C) chmod D) chown Answer: D Explanation: The chown command changes the ownership of a file or directory. Q77: What does the “umask” command do? A) Sets the default file permissions for new files B) Changes file ownership C) Lists user groups D) Displays system logs Answer: A Explanation: The umask command defines the default permission bits for newly created files and directories. Q78: Which command is used to create a symbolic link in Unix? A) link - s B) ln - s C) symlink D) lns Answer: B Explanation: The ln command with the - s option creates a symbolic (soft) link. Q79: What distinguishes a hard link from a symbolic link in Unix? A) A hard link points to the data on disk while a symbolic link points to the file name B) A hard link can span file systems while a symbolic link cannot C) A symbolic link is permanent whereas a hard link is temporary D) A symbolic link increases file size while a hard link does not Answer: A

C) Compiling code into binary D) Changing file ownership Answer: B Explanation: Pattern matching uses wildcards and regular expressions to compare and find string patterns. Q86: What is the significance of the “grep - i” option? A) It inverts the search results B) It performs a case-insensitive search C) It counts matching lines D) It displays only filenames Answer: B Explanation: The - i option makes grep perform case-insensitive searches. Q87: Which command is used to replace text in a file using stream editing? A) sed B) awk C) grep D) cut Answer: A Explanation: The sed command is used to find and replace text within files. Q88: How can you extract a column from a text file using the “cut” command? A) By specifying the column delimiter and field number B) By using the - column option C) By piping the file to grep D) By renaming the file extension Answer: A Explanation: The cut command extracts specific columns by setting the delimiter and specifying the field number. Q89: In a conditional test, which operator is used for numeric equality? A) = B) == C) - eq D) equals Answer: C Explanation: The - eq operator is used to test numeric equality in shell scripts. Q90: What does the “else” clause in an if statement do? A) It executes code when the if condition is false B) It checks additional conditions C) It terminates the script D) It displays an error message Answer: A Explanation: The else clause provides an alternative block of code that executes if the if condition evaluates to false.

Q91: Which logical operator is used to combine two conditions where both must be true? A) || B) && C) !! D) %% Answer: B Explanation: The && operator ensures that both conditions must be true for the combined expression to be true. Q92: What is the role of error handling in shell scripts? A) To improve script performance B) To manage and respond to unexpected conditions or failures C) To encrypt sensitive data D) To create new files automatically Answer: B Explanation: Error handling allows scripts to gracefully manage failures and unexpected inputs. Q93: How can you check if a file is readable in a shell script? A) Using the - r test operator B) Using the - w test operator C) Using the - x test operator D) Using the - f test operator Answer: A Explanation: The - r operator tests if a file is readable by the current user. Q94: Which operator is used to test if a file is executable? A) - e B) - f C) - x D) - d Answer: C Explanation: The - x operator checks if the file has executable permissions. Q95: What is the advantage of using “set - e” in a shell script? A) It enables command tracing B) It makes the script exit immediately if any command fails C) It allows the script to run in the background D) It increases script speed Answer: B Explanation: The “set - e” option forces the script to exit when a command returns a non-zero exit status, aiding error detection. Q96: Which command is used to declare an indexed array in Bash? A) array() B) declare - a C) newarray D) set array

B) chown C) chmod D) chgroup Answer: A Explanation: The chgrp command changes the group ownership of a file or directory. Q103: How do you list file permissions in Unix? A) ls - l B) ls - a C) ls - p D) ls - h Answer: A Explanation: The ls - l command displays detailed information including file permissions. Q104: What is the purpose of the “passwd” command in Unix? A) To change a user’s password B) To display file contents C) To list all users D) To modify file permissions Answer: A Explanation: The passwd command is used to change the password for a user account. Q105: Which command is used to add a new user in Unix? A) useradd B) newuser C) adduser D) mkuser Answer: A Explanation: The useradd command creates a new user account in Unix. Q106: What does the “ps” command display in Unix? A) File permissions B) Running processes C) User accounts D) Disk usage Answer: B Explanation: The ps command shows information about currently running processes. Q107: Which command is used to terminate a process by its process ID (PID)? A) stop B) kill C) end D) terminate Answer: B Explanation: The kill command sends a signal to a process to terminate it.

Q108: How do you run a process in the background in Unix? A) Append an & at the end of the command B) Use the bg command only C) Use the nohup command only D) Prepend the command with background Answer: A Explanation: Adding an “&” at the end of a command runs it in the background. Q109: Which command shows a hierarchical view of processes in Unix? A) ps B) pstree C) top D) htop Answer: B Explanation: The pstree command displays processes in a tree-like format, showing parent-child relationships. Q110: What is the purpose of the “wait” command in shell scripting? A) To pause execution for a fixed time B) To wait for background processes to finish C) To delay user input D) To synchronize file writes Answer: B Explanation: The wait command suspends script execution until specified background processes complete. Q111: Which command is used to adjust process priority in Unix? A) nice B) renice C) both A and B D) priority Answer: C Explanation: Both nice (to start a process with a given priority) and renice (to change the priority of a running process) are used for process priority adjustments. Q112: What does the pipe operator (|) do in Unix? A) Redirects output to a file B) Sends the output of one command as input to another C) Terminates a command D) Combines two files Answer: B Explanation: The pipe operator allows the output of one command to be used as the input for another command. Q113: Which command displays system memory usage in Unix? A) df B) free