nerdexam
LPI

010-100 · Question #23

010-100 Question #23: Real Exam Question with Answer & Explanation

The correct answer is C. echo "QUIDQUIDAGIS" > foobar.txt. The > redirection operator overwrites the destination file with the command output, while >> appends to it.

Question

Which of the following command sequences overwrites the file foobar.txt?

Options

  • Aecho "QUIDQUIDAGIS" >> foobar.txt
  • Becho "QUIDQUIDAGIS" < foobar.txt
  • Cecho "QUIDQUIDAGIS" > foobar.txt
  • Decho "QUIDQUIDAGIS" | foobar.txt

Explanation

The > redirection operator overwrites the destination file with the command output, while >> appends to it.

Common mistakes.

  • A. The >> operator appends output to the end of an existing file rather than overwriting it.
  • B. The < operator redirects a file as standard input to a command; it does not write output to foobar.txt.
  • D. The | operator pipes output from one command to another command's standard input; foobar.txt is a file, not a command, so this would result in an error.

Concept tested. Shell output redirection overwrite vs append

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

Community Discussion

No community discussion yet for this question.

Full 010-100 Practice