

















































































Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!


















































































Question 1. Which file is read by Bash for interactive non‑login shells to set aliases and functions? A) /etc/profile B) ~/.bashrc C) ~/.bash_profile D) /etc/bash.bashrc Answer: B Explanation: ~/.bashrc is executed for each interactive non‑login Bash session, making it the usual place for user‑defined aliases and functions. Question 2. What does the environment variable $PATH contain? A) The current working directory B) A list of directories Bash searches for executable files C) The user’s login name D) The system’s hostname Answer: B Explanation: $PATH is a colon‑separated list of directories that the shell searches when a command is entered without an absolute path. Question 3. Which command creates a permanent alias that is available in every new terminal session? A) alias ll='ls - l' B) echo "alias ll='ls - l'" >> ~/.bashrc C) set alias ll='ls - l' D) export alias ll='ls - l' Answer: B
Explanation: Adding the alias definition to ~/.bashrc ensures it is sourced each time a new interactive shell starts. Question 4. Which of the following files is executed by Bash for login shells? A) ~/.bashrc B) ~/.bash_logout C) ~/.profile D) /etc/bash_completion.d Answer: C Explanation: For login shells Bash reads /etc/profile and then the first of ~/.bash_profile, ~/.bash_login, or ~/.profile that exists. Question 5. How can you make a variable named DATA available to child processes? A) DATA=foo B) export DATA=foo C) set DATA=foo D) readonly DATA=foo Answer: B Explanation: The export command marks the variable for inclusion in the environment of subsequently executed commands. Question 6. Which command displays all current environment variables? A) set B) env C) printenv D) All of the above
Answer: B Explanation: HISTSIZE controls the number of commands stored in memory for the current session; when the session ends, only that many are written to the history file. Question 10. In a command line, which part is the “option” or “flag”? A) The first word (the command) B) The string that begins with a hyphen, e.g., -l in ls - l C) The pathname arguments D) The output redirection symbols Answer: B Explanation: Options (also called flags) modify command behavior and are typically prefixed with a hyphen. Question 11. What is the result of the command echo $(date)? A) Prints the literal string $(date) B) Executes date and substitutes its output into the echo command C) Causes a syntax error D) Prints the current working directory Answer: B Explanation: The $(...) syntax performs command substitution, replacing it with the command’s output before echo runs. Question 12. Which of the following is a built‑in Bash command? A) grep
B) cd C) tar D) ls Answer: B Explanation: cd changes the shell’s current directory and is implemented internally; external commands like grep, tar, and ls are separate binaries. Question 13. How can you view the manual page for the chmod command? A) man chmod B) chmod --help C) info chmod D) Both A and C Answer: D Explanation: man chmod opens the manual page; info chmod accesses the GNU info documentation. Both provide detailed information. Question 14. While reading a man page, which key scrolls down one page? A) j B) Spacebar C) b D) h Answer: B Explanation: In the pager less, which is used by man, the Spacebar advances one full screen. Question 15. What does the command grep - i "error" logfile do? A) Searches for the exact string “error” (case‑sensitive)
Answer: B Explanation: ~ expands to the value of $HOME, i.e., the user’s home directory. Question 19. Which of the following commands creates the directory path /opt/data/logs in one step, creating any missing parent directories? A) mkdir /opt/data/logs B) mkdir - p /opt/data/logs C) mkdir - r /opt/data/logs D) mkdir --parents /opt/data/logs Answer: B Explanation: -p (or --parents) tells mkdir to create all missing intermediate directories. Question 20. To remove a non‑empty directory and all its contents, which command is appropriate? A) rmdir dir_name B) rm - r dir_name C) rm dir_name/* D) del - rf dir_name Answer: B Explanation: rm - r recursively deletes a directory and everything inside it. Question 21. Which command updates the timestamps of an existing file without modifying its contents? A) cp file file B) touch file C) echo "" > file
D) chmod +t file Answer: B Explanation: touch changes the access and modification times; if the file does not exist it creates an empty one. Question 22. In the output of ls - l, what does the first character ‘l’ indicate? A) Regular file B) Directory C) Symbolic (soft) link D) Socket Answer: C Explanation: In long format, ‘l’ denotes a symbolic link; ‘-’ is a regular file, ‘d’ a directory. Question 23. Which command creates a hard link named linkfile pointing to original.txt? A) ln - s original.txt linkfile B) ln original.txt linkfile C) cp original.txt linkfile D) mv original.txt linkfile Answer: B Explanation: ln without -s creates a hard link that points to the same inode as the target file. Question 24. What limitation applies to hard links on most Linux systems? A) They cannot span different filesystems. B) They cannot be created for directories. C) Both A and B.
B) make 2> errors.log C) make > errors.log D) make &> errors.log Answer: B Explanation: 2> redirects file descriptor 2 (stderr) to the specified file. Question 28. Which syntax correctly appends the output of echo "Done" to the file log.txt? A) echo "Done" > log.txt B) echo "Done" >> log.txt C) echo "Done" 2>> log.txt D) echo "Done" &>> log.txt Answer: B Explanation: >> appends stdout to the target file without overwriting existing contents. Question 29. What does the pipeline ps aux | grep ssh accomplish? A) Lists all processes and filters lines containing “ssh”. B) Searches the file system for files named ssh. C) Starts the ssh daemon. D) Shows only the ssh process ID. Answer: A Explanation: ps aux lists processes; the pipe sends its output to grep ssh, which prints only matching lines. Question 30. Which command displays the first 20 lines of /var/log/syslog? A) head - n 20 /var/log/syslog
B) tail - n 20 /var/log/syslog C) cat - n 20 /var/log/syslog D) less +20 /var/log/syslog Answer: A Explanation: head - n 20 outputs the initial 20 lines of the file. Question 31. To continuously monitor a growing log file named app.log, which command is appropriate? A) tail - f app.log B) less app.log C) cat app.log | grep. D) tail - n 0 app.log Answer: A Explanation: tail - f follows the file, printing new data as it is appended. Question 32. Which command prints the number of lines, words, and characters in notes.txt? A) count notes.txt B) wc notes.txt C) grep - c '' notes.txt D) stat notes.txt Answer: B Explanation: wc (word count) reports lines, words, and bytes (or characters with -m). Question 33. How can you sort the contents of names.txt alphabetically and remove duplicate entries in a single command?
Question 36. Which option to grep enables recursive searching through directories? A) - R B) - r C) - a D) Both A and B (they behave the same). Answer: D Explanation: Both -r and -R cause grep to read all files under each directory recursively; -R also follows symbolic links. Question 37. What does the command tr 'a-z' 'A-Z' < file.txt accomplish? A) Translates all lowercase letters to uppercase in file.txt and writes to stdout. B) Replaces the string “a‑z” with “A‑Z”. C) Deletes all lowercase letters from file.txt. D) Counts the occurrences of each letter. Answer: A Explanation: tr translates characters; the range a-z is mapped to A-Z. Input is taken from file.txt via redirection. Question 38. Which command shows the manual entry for the printf built‑in, not the external program? A) man printf B) help printf C) info printf D) both A and C Answer: B
Explanation: help displays Bash built‑in documentation. man printf shows the external program’s man page (if any). Question 39. How can you list all environment variables that contain the word “PATH” in their name? A) env | grep PATH B) set | grep PATH C) printenv | grep PATH D) All of the above Answer: D Explanation: All three commands output environment variables; piping to grep PATH filters those containing “PATH”. Question 40. Which command displays the last 5 commands you entered, allowing you to edit the most recent one before execution? A) history 5 B) fc - l - 5 C) !! D) !- 5 Answer: B Explanation: fc - l - 5 lists the last 5 commands; invoking fc without arguments opens the most recent command in an editor for modification. Question 41. What does the Bash built‑in type - a ls display? A) The file type of ls (binary, alias, function, etc.) and all locations found in $PATH. B) Only the absolute path of ls. C) The manual page of ls.
A) man - k gcc B) whatis gcc C) info gcc D) man - f gcc Answer: D Explanation: man - f (or whatis) shows a brief description and the section numbers where a command’s manual page resides. Question 45. What does the umask 027 command set? A) Default permissions for newly created files to 750. B) Default permissions for newly created files to 640. C) Default permissions for newly created files to 664. D) No effect; umask must be a three‑digit octal number without leading zero. Answer: B Explanation: umask subtracts bits from the default 666 (files) and 777 (directories). 027 removes write for group and all permissions for others, yielding 640 for files. Question 46. Which symbolic chmod expression adds execute permission for the group and others on a file named script.sh? A) chmod +x script.sh B) chmod go+x script.sh C) chmod u+x script.sh D) chmod a+x script.sh Answer: B Explanation: go+x adds execute (x) permission for group (g) and others (o) only.
Question 47. How do you set the SUID bit on the executable runme? A) chmod u+s runme B) chmod +s runme C) chmod 4755 runme D) Both A and C are correct. Answer: D Explanation: u+s sets the set‑uid bit; 4755 is the octal representation (4 for SUID plus 755 for normal permissions). Question 48. Which command displays the numeric (UID, GID) and group memberships of the current user? A) whoami B) id C) groups D) getent passwd $USER Answer: B Explanation: id prints the user’s UID, primary GID, and all supplementary group IDs. Question 49. If a file has permissions -rw-r-----, which users can write to it? A) Owner only B) Owner and group C) Owner, group, and others D) No one can write to it Answer: A Explanation: The write bit (w) is set only for the owner (rw-); the group has read only (r--), others have none (---).
Explanation: Each command extracts the username field (first colon‑separated field) from the passwd file. Question 53. How can you list all files in the current directory that are larger than 10 MiB? A) find. - size +10M B) ls - l | awk '$5 > 10485760' C) du - h. | grep '^10M' D) find. - size +10k Answer: A Explanation: -size +10M matches files greater than 10 MiB; find works recursively from the current directory. Question 54. Which command searches for the string “ERROR” in all .log files under /var/log ignoring case? A) grep - i "ERROR" /var/log/.log B) grep - ri "ERROR" /var/log/.log C) grep - i "ERROR" - R /var/log/.log D) grep - i "ERROR" - r /var/log/.log Answer: D Explanation: -r makes the search recursive; -i ignores case. The pattern works on all files under /var/log. Question 55. What does the tee command do when used as command | tee file.txt? A) Writes the output of command to file.txt and also passes it to stdout. B) Redirects stdin of command from file.txt. C) Overwrites file.txt with the contents of command and discards stdout.
D) Appends command’s output to file.txt without displaying it. Answer: A Explanation: tee copies its standard input to both standard output and the specified file. Question 56. Which option to sort performs a “human‑numeric” sort (e.g., 2, 10, 100)? A) - n B) - h C) - g D) - V Answer: B Explanation: -h (or --human-numeric-sort) understands suffixes like K, M, G and sorts numbers in a way humans expect. Question 57. What is the purpose of the noclobber option in Bash? A) Prevents overwriting existing files with redirection (>). B) Disallows creation of hard links. C) Stops Bash from creating core dumps. D) Blocks the use of the rm command. Answer: A Explanation: set - o noclobber (or set - C) makes > fail if the target file already exists, protecting data. Question 58. Which command prints the 10th line of a file named data.txt? A) head - n 10 data.txt | tail - n 1 B) tail - n 10 data.txt | head - n 1 C) sed - n '10p' data.txt