6.
What is the surest way to run a program (say, myprog) that’s located in the current working
directory?
- A.Type ./ followed by the program name: ./myprog.
- B.Type the program name alone: myprog.
- C.Type run followed by the program name: run myprog.
- D.Type /. followed by the program name: /.myprog.
- E.Type the program name followed by an ampersand (&): myprog &.
- Answer & Explanation
- Report
Answer : [A]
Explanation :
Explanation :
The dot (.) character refers to the current working directory, and the slash (/) is a directory separator. Thus, preceding a program name by ./ unambiguously identifies the intention to run the program that’s stored in the current directory. Option B will run the first instance of the program that’s found on the current path. Because paths often omit the current directory for security reasons, this option is likely to fail. The run command isn’t a standard Linux command, so option C is unlikely to do anything, much less what the question specifies. Option D would be correct except that it reverses the order of the two characters. The effect is to attempt to run the .myprog file in the root (/) directory. This file probably doesn’t exist, and even if it did, it’s not the file the question specifies should be run. Option E runs the first instance of myprog found on the path, and additionally it runs the program in the background. (Chapter 2 covers background execution in more detail.) |
7.
How does man display information by default on most Linux systems?
- A.Using a custom X-based application
- B.Using the Firefox Web browser
- C.Using the info browser
- D.Using the Vi editor
- E.Using the less pager
- Answer & Explanation
- Report
Answer : [E]
Explanation :
Explanation :
By default, man uses the less pager to display information on most Linux systems, so option E is correct. Although an X-based version of man does exist (xman), the basic man doesn’t use a custom X-based application (option A), nor does it use Firefox (option B) or the Vi editor (option D). The info command is a competing documentation system to man, so option C is incorrect. |
8.
You want to store the standard output of the ifconfig command in a text file (file.txt)
for future reference, and you want to wipe out any existing data in the file. You do not
want to store standard error in this file. How can you accomplish these goals?
- A.ifconfig < file.txt
- B.ifconfig >> file.txt
- C.ifconfig > file.txt
- D.ifconfig | file.txt
- E.ifconfig 2> file.txt
- Answer & Explanation
- Report
Answer : [C]
Explanation :
Explanation :
The > redirection operator stores a command’s standard output in a file, overwriting the contents of any existing file by the specified name, so option C is correct. Option A specifies the standard input redirection so that ifconfig will take the contents of file .txt as input. Option B is almost correct; the >> redirection operator redirects standard output, as requested, but it appends data to the specified file rather than overwriting it. Option D specifies a pipe; the output of ifconfig is sent through the file.txt program, if it exists. (Chances are it doesn’t, so you’d get a command not found error message.) Option E redirects standard error, rather than standard output, to file.txt, and so is incorrect. |
9.
What is the effect of the following command?
$ myprog &> input.txt
$ myprog &> input.txt
- A.Standard error to myprog is taken from input.txt.
- B.Standard input to myprog is taken from input.txt.
- C.Standard output and standard error from myprog are written to input.txt.
- D.All of the above.
- E.None of the above.
- Answer & Explanation
- Report
Answer : [C]
Explanation :
Explanation :
The &> redirection operator sends both standard output and standard error to the specified file, as option C states. (The name of the file, input.txt, is intentionally deceptive, but the usage is still valid.) Option A mentions standard error but describes it as if it were an input stream, which it’s not; it’s an output stream. Option B mentions standard input, but the &> operator doesn’t affect standard input. Because only option C is correct, neither option D nor E can be correct. |
10.
How many commands can you pipe together at once?
- A.2
- B.3
- C.4
- D.16
- E.An arbitrary number
- Answer & Explanation
- Report
Answer : [E]
Explanation :
Explanation :
In principle, you can pipe together as many commands as you like. (In practice, of course, there will be limits based on input buffer size, memory, and so on, but these limits are far higher than the 2, 3, 4, or 16 commands specified in options A, B, C, and D.) |