010-100 · Question #12
In order to append the output of ls to a file called bazz, which of the following command lines would you use?
The correct answer is D. ls >> bazz. The >> operator appends stdout to a file without truncating existing content, making it the correct choice for adding output to an existing file.
Question
In order to append the output of ls to a file called bazz, which of the following command lines would you use?
Options
- Als >bazz
- Bls >& bazz
- Cls &> bazz
- Dls >> bazz
How the community answered
(38 responses)- A11% (4)
- B13% (5)
- C5% (2)
- D71% (27)
Why each option
The >> operator appends stdout to a file without truncating existing content, making it the correct choice for adding output to an existing file.
The single > operator truncates the file to zero bytes before writing, destroying any content already in bazz.
The >& operator redirects both stdout and stderr to the file but opens it in overwrite mode, not append mode.
The &> operator also redirects both stdout and stderr in overwrite mode, not append mode.
The >> redirection operator opens the target file in append mode, writing new output after any existing content rather than overwriting it. Running ls >> bazz adds the directory listing to the end of bazz and creates the file if it does not already exist.
Concept tested: Bash append output redirection operator
Source: https://www.gnu.org/software/bash/manual/bash.html#Redirecting-Output
Topics
Community Discussion
No community discussion yet for this question.