QUIZ(1) Linux Foundations QUIZ(1)

Quiz

Redirection and pipes

10 questions | 20 minutes | Closed book, no terminal

Assume a RHEL 9 system and a bash shell throughout.


1. Which operator adds output to the end of an existing file without erasing what's already there?

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


2. What is printed by the last command?

$ echo "hello" > notes.txt
$ echo "world" > notes.txt
$ cat notes.txt

A. world B. hello C. hello then world D. Nothing — the file is empty


3. A command writes an error message to the screen. Which stream is it using?

A. stdin B. stderr C. stdout D. /dev/null


4. What appears on screen?

$ ls /this/path/does/not/exist 2> /dev/null

A. An error message B. A listing of / C. The text /dev/null D. Nothing


5. A student wants to save a command's normal output to out.txt and its error messages to err.txt, in two separate files. Which is correct?

A. command > out.txt 2> err.txt B. command > out.txt > err.txt C. command >> out.txt err.txt D. command | out.txt | err.txt


6. What does this pipeline report?

$ cat /etc/passwd | wc -l

A. The size of /etc/passwd in bytes B. The number of words in /etc/passwd C. The number of lines in /etc/passwd D. The number of user accounts currently logged in


7. A student runs the following and is surprised the error message still appears on screen instead of going into results.txt:

$ ls /etc /nope | grep conf > results.txt

Why?

A. grep deleted the error message B. > only works at the start of a command C. /nope is not a valid argument to ls D. A pipe carries stdout only, so the error went straight to the terminal


8. Which counts how many lines in /etc/passwd contain the text bash?

A. grep bash /etc/passwd | wc -l B. wc -l /etc/passwd | grep bash C. cat /etc/passwd > grep bash > wc -l D. grep /etc/passwd bash | wc -l


9. A regular user runs:

$ sudo echo "127.0.0.1 testhost" > /etc/hosts

and gets bash: /etc/hosts: Permission denied, despite using sudo. What happened?

A. sudo doesn't work with echo B. The redirect is performed by the user's own shell, which is not running as root C. /etc/hosts is immutable and cannot be edited D. The password was entered incorrectly


10. (Stretch) These two are not equivalent. What does the second one do?

$ command > log.txt 2>&1
$ command 2>&1 > log.txt

A. They are equivalent; order never matters B. Sends both streams to the terminal C. Sends stderr to log.txt and stdout to the terminal D. Sends stderr to the terminal and stdout to log.txt

---