LX0-103 · Question #157
In order to append the output of Is to a file called bazz, which of the following command lines would you use?
The correct answer is D. Is ?bazz. To append command output to a file in bash, the >> operator is used rather than > which overwrites. Choice D (ls >> bazz) is the correct append syntax, where the >> symbol likely rendered as a single character due to encoding.
Question
In order to append the output of Is to a file called bazz, which of the following command lines would you use?
Options
- AIs > bazz
- BIs >&bazz
- CIs &> bazz
- DIs ?bazz
How the community answered
(39 responses)- A3% (1)
- B3% (1)
- C5% (2)
- D90% (35)
Why each option
To append command output to a file in bash, the >> operator is used rather than > which overwrites. Choice D (ls >> bazz) is the correct append syntax, where the >> symbol likely rendered as a single character due to encoding.
The single > operator truncates and overwrites the target file rather than appending to it, destroying any existing content.
The >&file syntax is used to redirect one file descriptor to another file descriptor, not a valid method for appending output to a named file.
The &> operator redirects both stdout and stderr to a file but overwrites the file rather than appending to it.
The >> operator appends stdout to an existing file without truncating its contents. Using ls >> bazz adds the directory listing to the end of bazz, preserving any data already in the file. This is the standard POSIX shell mechanism for non-destructive output redirection.
Concept tested: Shell output append redirection operator usage
Source: https://www.gnu.org/software/bash/manual/bash.html#Redirections
Topics
Community Discussion
No community discussion yet for this question.