nerdexam
LPI

010-100 · Question #23

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

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

The Power of the Command Line

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

How the community answered

(24 responses)
  • A
    8% (2)
  • C
    79% (19)
  • D
    13% (3)

Why each option

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

Aecho "QUIDQUIDAGIS" >> foobar.txt

The >> operator appends output to the end of an existing file rather than overwriting it.

Becho "QUIDQUIDAGIS" < foobar.txt

The < operator redirects a file as standard input to a command; it does not write output to foobar.txt.

Cecho "QUIDQUIDAGIS" > foobar.txtCorrect

The > operator redirects standard output to a file and truncates (overwrites) any existing content in that file before writing. This causes foobar.txt to contain only the new string QUIDQUIDAGIS after execution.

Decho "QUIDQUIDAGIS" | foobar.txt

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

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

Topics

#output redirection#overwrite operator#echo command#shell redirection

Community Discussion

5
Mei-Ling H.Mei-Ling H.Feb 6, 2026

C is correct. The single greater-than sign redirects standard output to the file and truncates it first, so whatever was in foobar.txt before is gone and replaced with QUIDQUIDAGIS. The double greater-than in A appends instead of overwrites, B tries to redirect the file as input into echo which does not make sense, and D pipes to a filename which is not a valid command.

18
Nina C.Nina C.Feb 8, 2026

Good breakdown, and one thing worth adding for the exam is that the single redirect will also create foobar.txt from scratch if it does not already exist, so it acts as both a create and an overwrite depending on whether the file was there before.

0
Nina C.Nina C.Feb 20, 2026

So if I'm reading this right, the single greater-than sign is what actually replaces whatever was already in the file, while two of them just adds to the end, so wouldn't that make C the one that overwrites? And just to make sure I have this straight, does the direction the arrow points matter here, or is it purely about how many you use?

3
Fatima Z.Fatima Z.Jan 28, 2026

I almost circled A because those double arrows looked way more aggressive, like they would bulldoze the whole file, but then my little hook kicked in, ONE arrow is a funnel that flushes the file empty and pours fresh content in, TWO arrows just tacks new text onto the end like a sticky note on top of what is already there. So lock it in with this image, a single greater-than sign is a drain that empties the tub before refilling it, and C is your overwriter every single time.

1
Mei-Ling H.Mei-Ling H.Jan 31, 2026

Good image but flip the labels, single arrow is the one that overwrites and double arrow is the append, so C is right but call it the drain that empties first, not a sticky note.

0
Full 010-100 Practice