

















































































Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
This certification exam focuses on the skills and knowledge required to write shell scripts for Linux-based systems. The exam tests proficiency in handling file operations, working with system utilities, managing processes, and automating tasks using Bash and other shell scripting languages. Candidates will demonstrate their ability to write effective scripts to solve common system administration tasks, including automation, monitoring, and system performance tuning.
Typology: Exams
1 / 89
This page cannot be seen from the preview
Don't miss anything!


















































































Question 1. Which shebang line explicitly requests the Bash interpreter located in the system's PATH? A) #!/bin/bash B) #!/usr/bin/env bash C) #!/bin/sh D) #!/usr/local/bin/bash Answer: B Explanation: #!/usr/bin/env bash uses the env command to locate bash in the user's PATH, making the script portable across systems where Bash may reside in different directories. Question 2. In a script, which of the following commands will execute a command without creating a subshell? A) $(command) B) `command` C) command | cat D) command && other Answer: D Explanation: The && operator runs the second command in the same shell after the first succeeds, whereas command substitution and pipelines spawn subshells. Question 3. Which file is read only for login shells of the root user on most Linux distributions? A) /root/.bashrc B) /etc/profile C) /root/.bash_profile D) /etc/bash.bashrc
Answer: C Explanation: /root/.bash_profile (or .profile) is sourced for login shells of the root user; .bashrc is for interactive non‑login shells. Question 4. What does the following pipeline do? ps aux | grep '^root' | awk '{print $2}' A) Lists PIDs of processes owned by root B) Shows the command line of root processes C) Counts the number of root processes D) Displays memory usage of root processes Answer: A Explanation: ps aux lists all processes, grep '^root' filters lines starting with “root”, and awk '{print $2}' prints the second field, which is the PID. Question 5. Which redirection sends both standard output and standard error to the same file, overwriting it? A) command > file 2>&1 B) command &> file C) command >> file 2>&1 D) command > file Answer: B Explanation: &> redirects both stdout and stderr to the file, truncating it. Option A also redirects both but uses separate syntax; both are correct, but &> is the concise form. Question 6. What is the numeric file descriptor for standard error? A) 0 B) 1
B) set - f C) set - u D) set - x Answer: B Explanation: set - f (or set - o noglob) turns off filename expansion, treating *, ?, and [ literally. Question 10. What does the test expression [[ - d "$DIR" && - r "$DIR" ]] evaluate? A) Whether $DIR is a regular file and readable B) Whether $DIR exists, is a directory, and is readable C) Whether $DIR is a symbolic link D) Whether $DIR is empty Answer: B Explanation: -d checks for a directory, -r checks readability; && requires both conditions to be true. Question 11. Which command sends a SIGTERM to a process with PID stored in variable pid? A) kill - 9 $pid B) kill - 15 $pid C) kill - s SIGTERM $pid D) Both B and C are correct Answer: D Explanation: Signal number 15 corresponds to SIGTERM; both kill - 15 and kill - s SIGTERM send the same signal.
Question 12. How can you run a command in the background and immediately disown it so it does not receive a SIGHUP when the terminal closes? A) command & B) command & disown C) nohup command & D) Both B and C are correct Answer: D Explanation: command & disown removes the job from the shell’s job table; nohup starts the command immune to SIGHUP. Both achieve the goal. Question 13. Which of the following is a best practice for naming a Bash script file? A) Use all uppercase letters B) Include spaces to improve readability C) Use lowercase letters, numbers, hyphens, and end with .sh D) Name it script without extension Answer: C Explanation: Lowercase with hyphens and a .sh extension follows convention and avoids issues with spaces or case sensitivity. Question 14. In a script, $@ expands to: A) All positional parameters as a single word B) All positional parameters, each quoted separately C) The number of arguments passed D) The name of the script itself Answer: B
C) Iterates over files named 1 to 5 D) Generates a syntax error Answer: A Explanation: Brace expansion {1..5} creates the list 1 2 3 4 5; the for loop echoes each. Question 18. Which construct will repeat a block until a command succeeds? A) while true; do command; done B) until command; do :; done C) while! command; do :; done D) Both B and C are correct Answer: D Explanation: until command runs the block while the command’s exit status is non‑zero; while ! command does the same with explicit negation. Question 19. Inside a Bash function, what does the local keyword achieve? A) Declares a global variable B) Makes the variable read‑only C) Limits the variable’s scope to the function D) Exports the variable to child processes Answer: C Explanation: local creates a variable whose visibility is restricted to the function where it is defined. Question 20. How can you source another script named utils.sh from the current script? A) ./utils.sh
B) source utils.sh C) . utils.sh D) Both B and C are correct Answer: D Explanation: Both source utils.sh and . utils.sh read and execute the file in the current shell context. Question 21. Which regular expression matches a three‑digit number using grep - E? A) [0-9]{3} B) \d{3} C) [[:digit:]]{3} D) Both A and C are correct Answer: D Explanation: In extended regex, {3} quantifier works with character classes; both [0-9]{3} and [[:digit:]]{3} match exactly three digits. \d is not portable in basic/extended grep. Question 22. In sed 's/^\(.*\)$/\U\1/' file, what does \U do? A) Converts the matched text to uppercase B) Undoes the previous substitution C) Prints the line number D) Replaces with a literal “U” Answer: A Explanation: \U in GNU sed forces the following text to uppercase until \E or end of replacement. Question 23. Which awk built‑in variable contains the current record number?
Question 26. How can you capture the exit status of a pipeline as a whole, not just the last command? A) Use set - e B) Use PIPESTATUS array C) Append && true to the pipeline D) Use set - o pipefail Answer: D (and B also works, but D directly changes behavior) Explanation: set - o pipefail causes the pipeline’s exit status to be the status of the rightmost command that fails, allowing detection of any failure. Question 27. Which command safely creates a temporary file and prints its name? A) tempfile B) mktemp C) touch /tmp/tmpfile D) dd if=/dev/zero of=/tmp/tmpfile bs=1 count=0 Answer: B Explanation: mktemp atomically creates a unique temporary file and returns its pathname. Question 28. When using trap, which signal number corresponds to SIGINT? A) 1 B) 2 C) 3 D) 15 Answer: B Explanation: Signal 2 is SIGINT, generated by Ctrl‑C.
Question 29. Which of the following chmod symbolic modes adds the setuid bit while removing group write permission? A) chmod u+s,g-w file B) chmod +s,g-w file C) chmod 4750 file D) Both A and C are correct Answer: D Explanation: u+s,g-w adds setuid (s for user) and removes group write. Numeric mode 4750 also sets setuid (4) and clears group write. Question 30. In a cron entry, what does the field */15 in the minute position mean? A) Run at minute 15 of every hour B) Run every 15 minutes C) Run at minutes 0, 15, 30, 45 of every hour D) Both B and C are correct Answer: D Explanation: */15 expands to 0,15,30,45 – effectively “every 15 minutes”. Question 31. Which command displays only the usernames of all users currently logged in? A) who | awk '{print $1}' B) users C) w - h D) Both A and B are correct Answer: D
D) set - n Answer: B Explanation: set - x (or set - o xtrace) prints each command with its expanded arguments. Question 35. What does the -n option to bash do? A) Execute the script without reading input B) Perform a syntax check without executing commands C) Enable noclobber for redirection D) Disable pathname expansion Answer: B Explanation: bash - n script.sh parses the script for syntax errors but does not run it. Question 36. Which of the following is not a valid associative array declaration in Bash 4+? A) declare - A colors B) declare - a colors C) colors=([red]="#FF0000" [green]="#00FF00") D) declare - A colors=([blue]="#0000FF") Answer: B Explanation: -a creates an indexed array, not an associative one. The others correctly declare associative arrays. Question 37. How can you limit the number of lines awk reads from a file to the first 10? A) awk 'NR<=10' file B) head - 10 file | awk '{print}'
C) awk 'FNR==10{exit}' file D) Both A and C are correct Answer: D Explanation: NR<=10 prints first 10 lines; alternatively, exiting when FNR==10 stops processing after line 10. Question 38. Which command recursively finds all regular files larger than 100 MiB in /var? A) find /var - type f - size +100M B) find /var - size +100M - type f C) find /var - type f - size +100M - exec ls - lh {} \; D) Both A and B are correct Answer: D Explanation: The order of options does not matter; both forms locate regular files (-type f) larger than 100 MiB (+100M). Question 39. In Bash, what does the parameter expansion ${var:-default} do? A) Assigns default to var if var is unset or null B) Substitutes default only if var is unset or null, leaving var unchanged C) Forces var to be read‑only D) Trims whitespace from var Answer: B Explanation: :- provides a default value for expansion without assigning it to the variable. Question 40. Which statement about set - u is true? A) It treats unset variables as an error when expanding
FSOFSRSORSAnswer: A Explanation: FS defines how awk splits each input line into fields. Question 44. Which of the following commands appends the output of ls to a file named list.txt without overwriting existing content? A) ls > list.txt B) ls >> list.txt C) ls | tee - a list.txt D) Both B and C are correct Answer: D Explanation: >> appends; tee - a also appends while also displaying to stdout. Question 45. In a Bash script, what does the construct exec 3>&1 achieve? A) Opens file descriptor 3 for reading from stdin B) Duplicates stdout (fd 1) onto fd 3 C) Closes file descriptor 3 D) Redirects stderr to stdout Answer: B Explanation: 3>&1 makes fd 3 a copy of stdout, allowing later restoration or separate redirection.
Question 46. Which sed command in‑place edits a file, creating a backup with extension .bak? A) sed - i.bak 's/foo/bar/g' file B) sed - i 's/foo/bar/g' file.bak C) sed - i 's/foo/bar/g' file > file.bak D) sed - i - b 's/foo/bar/g' file Answer: A Explanation: -i.bak tells sed to edit in place while saving the original as file.bak. Question 47. Which of the following statements about nohup is correct? A) It runs a command immune to SIGHUP and redirects output to nohup.out by default B) It runs a command in the background automatically C) It prevents a command from receiving SIGTERM D) It is equivalent to disown Answer: A Explanation: nohup ignores SIGHUP; unless redirected, stdout/stderr go to nohup.out. It does not background the job. Question 48. How can you limit a Bash while loop to read only the first 5 lines of a file? A) while read line; do ...; done < file | head - 5 B) while read - r line && ((count++ < 5)); do ...; done < file C) head - 5 file | while read line; do ...; done D) Both B and C are correct Answer: D Explanation: Both approaches stop after processing five lines.
Explanation: uname - r prints the release string; /proc/version contains the full version line. Question 52. Which awk option automatically sets the output field separator to a comma? A) -F, B) -v OFS=',' C) BEGIN{OFS=","} D) Both B and C are correct Answer: D Explanation: Setting OFS via -v or in a BEGIN block changes the output separator. Question 53. What does the -p option to mkdir do? A) Creates parent directories as needed B) Sets permissions to 0777 C) Prints a message after creation D) Creates a directory with a timestamped name Answer: A Explanation: mkdir - p creates the full path, ignoring errors if directories already exist. Question 54. Which of the following ensures that a Bash script runs with strict error handling? A) set - euo pipefail B) set - xv C) set - n D) set - a
Answer: A Explanation: -e aborts on error, -u treats unset variables as errors, and -o pipefail propagates failures in pipelines. Question 55. In a crontab line, which field specifies the day of the week? A) The first field B) The third field C) The fifth field D) The sixth field Answer: C Explanation: Crontab fields are minute, hour, day‑of‑month, month, day‑of‑week (the fifth). Question 56. Which command outputs the number of lines, words, and bytes of a file? A) wc - lwb file B) wc file C) stat - c %s file D) du - b file Answer: B Explanation: wc without options prints lines, words, and bytes (or characters depending on locale). Question 57. What does the -z test operator check? A) Whether a string is empty B) Whether a file exists C) Whether a variable is set