XK0-005 · Question #3
A systems administrator needs to append output of command to the contents of ls -lha /opt a test.txt file. Which of the following commands will accomplish this?
The correct answer is C. ls -lha /opt >> test.txt. To append the output of a command to an existing file in Linux, the append redirection operator >> is used.
Question
Options
- Als -lha /opt > test.txt
- Bls -lha /opt < test.txt
- Cls -lha /opt >> test.txt
- Dls -lha /opt << test.txt
How the community answered
(30 responses)- A3% (1)
- B7% (2)
- C90% (27)
Why each option
To append the output of a command to an existing file in Linux, the append redirection operator `>>` is used.
The `>` operator redirects the standard output of a command and overwrites the contents of the specified file if it already exists, rather than appending.
The `<` operator redirects the contents of a file as standard input to a command, which is the opposite of what is needed to append command output.
The `>>` operator redirects the standard output of a command and appends it to the end of the specified file. If the file `test.txt` does not exist, it will be created before the output is written.
The `<<` operator is used for a 'here document', providing multiple lines of input to a command until a specified delimiter is encountered, which is not applicable for appending command output.
Concept tested: Linux shell output redirection and appending
Source: https://www.gnu.org/software/bash/manual/bash.html#Redirections
Topics
Community Discussion
No community discussion yet for this question.