nerdexam
CompTIA

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.

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

(36 responses)
  • A
    3% (1)
  • B
    6% (2)
  • C
    89% (32)
  • D
    3% (1)

Why each option

This question tests knowledge of Linux shell output redirection operators, specifically the difference between overwrite and append.

Als -lha /opt > test.txt

The single > operator redirects output to a file but overwrites all existing contents rather than appending.

Bls -lha /opt < test.txt

The < operator redirects a file as standard input to a command, not output from a command to a file.

Cls -lha /opt >> test.txtCorrect

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.

Dls -lha /opt << test.txt

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

#output redirection#append operator#stdout#shell syntax

Community Discussion

No community discussion yet for this question.

Full XK0-004 Practice