nerdexam
LPI

010-100 · Question #12

In order to append the output of ls to a file called bazz, which of the following command lines would you use?

The correct answer is D. ls >> bazz. The >> operator appends stdout to a file without truncating existing content, making it the correct choice for adding output to an existing file.

The Power of the Command Line

Question

In order to append the output of ls to a file called bazz, which of the following command lines would you use?

Options

  • Als >bazz
  • Bls >& bazz
  • Cls &> bazz
  • Dls >> bazz

How the community answered

(38 responses)
  • A
    11% (4)
  • B
    13% (5)
  • C
    5% (2)
  • D
    71% (27)

Why each option

The >> operator appends stdout to a file without truncating existing content, making it the correct choice for adding output to an existing file.

Als >bazz

The single > operator truncates the file to zero bytes before writing, destroying any content already in bazz.

Bls >& bazz

The >& operator redirects both stdout and stderr to the file but opens it in overwrite mode, not append mode.

Cls &> bazz

The &> operator also redirects both stdout and stderr in overwrite mode, not append mode.

Dls >> bazzCorrect

The >> redirection operator opens the target file in append mode, writing new output after any existing content rather than overwriting it. Running ls >> bazz adds the directory listing to the end of bazz and creates the file if it does not already exist.

Concept tested: Bash append output redirection operator

Source: https://www.gnu.org/software/bash/manual/bash.html#Redirecting-Output

Topics

#output redirection#append operator#shell commands#ls

Community Discussion

No community discussion yet for this question.

Full 010-100 Practice