nerdexam
CompTIA

LX0-103 · Question #157

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

The correct answer is D. Is ?bazz. To append command output to a file in bash, the >> operator is used rather than > which overwrites. Choice D (ls >> bazz) is the correct append syntax, where the >> symbol likely rendered as a single character due to encoding.

GNU and Unix Commands

Question

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

Options

  • AIs > bazz
  • BIs >&bazz
  • CIs &> bazz
  • DIs ?bazz

How the community answered

(39 responses)
  • A
    3% (1)
  • B
    3% (1)
  • C
    5% (2)
  • D
    90% (35)

Why each option

To append command output to a file in bash, the >> operator is used rather than > which overwrites. Choice D (ls >> bazz) is the correct append syntax, where the >> symbol likely rendered as a single character due to encoding.

AIs > bazz

The single > operator truncates and overwrites the target file rather than appending to it, destroying any existing content.

BIs >&bazz

The >&file syntax is used to redirect one file descriptor to another file descriptor, not a valid method for appending output to a named file.

CIs &> bazz

The &> operator redirects both stdout and stderr to a file but overwrites the file rather than appending to it.

DIs ?bazzCorrect

The >> operator appends stdout to an existing file without truncating its contents. Using ls >> bazz adds the directory listing to the end of bazz, preserving any data already in the file. This is the standard POSIX shell mechanism for non-destructive output redirection.

Concept tested: Shell output append redirection operator usage

Source: https://www.gnu.org/software/bash/manual/bash.html#Redirections

Topics

#shell redirection#append output#ls command#command line

Community Discussion

No community discussion yet for this question.

Full LX0-103 Practice