XK0-004 · 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. This question tests knowledge of Linux shell output redirection operators, specifically the difference between overwrite and append.
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
(36 responses)- A3% (1)
- B6% (2)
- C89% (32)
- D3% (1)
Why each option
This question tests knowledge of Linux shell output redirection operators, specifically the difference between overwrite and append.
The single > operator redirects output to a file but overwrites all existing contents rather than appending.
The < operator redirects a file as standard input to a command, not output from a command to a file.
The >> operator appends standard output to an existing file without overwriting its contents. Running ls -lha /opt >> test.txt will add the directory listing to the end of test.txt, preserving any data already in the file.
The << operator is a here-document delimiter that reads input inline from the shell script itself, not a file append mechanism.
Concept tested: Linux shell output append redirection operator
Source: https://www.gnu.org/software/bash/manual/bash.html#Redirecting-Output
Topics
Community Discussion
No community discussion yet for this question.