nerdexam
CompTIA

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.

Scripting, Containers, and Automation

Question

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?

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)
  • A
    3% (1)
  • B
    7% (2)
  • C
    90% (27)

Why each option

To append the output of a command to an existing file in Linux, the append redirection operator `>>` is used.

Als -lha /opt > test.txt

The `>` operator redirects the standard output of a command and overwrites the contents of the specified file if it already exists, rather than appending.

Bls -lha /opt < test.txt

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.

Cls -lha /opt >> test.txtCorrect

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.

Dls -lha /opt << test.txt

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

#Command Line Interface#File Redirection#Shell Operators#Linux Commands

Community Discussion

No community discussion yet for this question.

Full XK0-005 Practice