11.
You want to run an interactive script, gabby, which produces a lot of output in response to
the user’s inputs. To facilitate future study of this script, you want to copy its output to a
file. How might you do this?
- A.gabby > gabby-out.txt
- B.gabby | tee gabby-out.txt
- C.gabby < gabby-out.txt
- D.gabby &> gabby-out.txt
- E.gabby `gabby-out.txt`
- Answer & Explanation
- Report
Answer : [B]
Explanation :
Explanation :
The tee command sends its output both to standard output and to a named file. Thus, placing the tee command (with an output filename) after another command and a pipe will achieve the desired effect. Options A and D redirect gabby’s output to a file, which means you won’t be able to see the output and interact with it. Option C sends the contents of gabby-out.txt to gabby as input, which isn’t what’s desired, either. Option E attempts to run gabby-out.txt as a program and use its output as command-line arguments to gabby, which is not what’s desired. |
12.
A text-mode program, verbose, prints a lot of spurious “error” messages to standard error.
How might you get rid of those messages while still interacting with the program?
- A.verbose | quiet
- B.verbose &> /dev/null
- C.verbose 2> /dev/null
- D.verbose > junk.txt
- E.quiet-mode verbose
- Answer & Explanation
- Report
Answer : [C]
Explanation :
Explanation :
The 2> redirection operator redirects standard error only, leaving standard output unaffected. Sending standard error to /dev/null gets rid of it. Thus, option C is correct. Option A pipes the standard output of verbose through the quiet program, which isn’t a standard Linux program. Option B sends both standard output and standard error to /dev/null, so you won’t be able to interact with the program, as the question specifies you must be able to do. Option D redirects standard output only to the junk.txt file, so once again, interaction will be impossible—and you’ll see the unwanted error messages on the screen. Option E’s quiet-mode program is fictitious (or at least non-standard), so this option is incorrect. |
13.
How do the > and >> redirection operators differ?
- A.The > operator creates a new file or overwrites an existing one; the >> operator creates a new file or appends to an existing one.
- B.The > operator creates a new file or overwrites an existing one; the >> operator appends to an existing file or issues an error message if the specified file doesn’t exist.
- C.The > operator redirects standard output; the >> operator redirects standard error.
- D.The > operator redirects standard output; the >> operator redirects standard input.
- E.The > operator writes to an existing file but fails if the file doesn’t exist; the >> operator writes to an existing file or creates a new one if it doesn’t already exist.
- Answer & Explanation
- Report
Answer : [A]
Explanation :
Explanation :
Option A correctly describes the difference between these two redirection operators. Option B is almost correct, but the >> operator will create a new file if one doesn’t already exist. The >> operator does not redirect standard error (as stated in option C) or standard input (as stated in option D). Both operators will create a new file if one doesn’t already exist, contrary to what option E states. |
14.
What program would you use to display the end of a configuration file?
- A.uniq
- B.cut
- C.tail
- D.wc
- E.fmt
- Answer & Explanation
- Report
Answer : [C]
Explanation :
Explanation :
The tail command displays the final 10 lines of a file, so option C is correct. (You can change the number of lines displayed with the -n option.) The uniq command (option A) removes duplicate lines from a list. The cut command (option B) echoes the specified characters or fields from an input text file. The wc command (option D) displays counts of the number of characters, words, and lines in a file. The fmt command (option E) is a plaintext formatter. |
15.
What is the effect of the following command?
$ pr report.txt | lpr
$ pr report.txt | lpr
- A.The file report.txt is formatted for printing and sent to the lpr program.
- B.The files report.txt and lpr are combined together into one file and sent to standard output.
- C.Tabs are converted to spaces in report.txt, and the result is saved in lpr.
- D.The file report.txt is printed, and any error messages are stored in the file lpr.
- E.None of the above.d
- Answer & Explanation
- Report
Answer : [A]
Explanation :
Explanation :
The pr program takes a text file as input and adds formatting features intended for printing, such as a header and blank lines to separate pages. The command also pipes the output through lpr (which is a Linux printing command). Option A describes these effects and so is correct. Option B describes the effect of the cat program, and so is incorrect. The conversion of tabs to spaces can be done by the expand program, so option C is incorrect. Although the specified command does print report.txt, error messages are not stored in the lpr file, so option D is incorrect. Because option A is correct, option E is incorrect. |