117-010 · Question #24
Which of the following commands redirects the output of cmd to the file foo.txt, in which an existing file is overwritten?
The correct answer is E. cmd > foo.txt. See the full explanation below for the reasoning.
Question
Which of the following commands redirects the output of cmd to the file foo.txt, in which an existing file is overwritten?
Options
- Acmd || foo.txt
- Bcmd | foo.txt
- Ccmd && foo.txt
- Dcmd >> foo.txt
- Ecmd > foo.txt
How the community answered
(20 responses)- A5% (1)
- B5% (1)
- C10% (2)
- E80% (16)
Community Discussion
6E is correct. The single greater-than sign redirects standard output to a file and overwrites whatever is already there, while the double greater-than in D appends instead of overwriting, and the other options are not redirection operators at all.
E is right, > overwrites while >> appends, but do you know what happens if foo.txt doesn't exist yet?
If foo.txt does not exist, both > and >> will create it, so the only real difference is what happens when the file is already there.
Single right-arrow overwrites, double appends. Saw E on my LPI exam, chose it cold.
E is right. Does it click why >> writes differently than > does?
E nails it, but do you know why >> does something different?