nerdexam
LPI

101-350 · Question #131

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

The correct answer is C. echo "QUIDQUIDAGIS" > foobar.txt. See the full explanation below for the reasoning.

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

(44 responses)
  • A
    7% (3)
  • B
    9% (4)
  • C
    82% (36)
  • D
    2% (1)

Community Discussion

7
Devraj B.Devraj B.May 15, 2026

The answer is C. The single greater-than symbol is the standard output redirect operator in bash, and it truncates the target file to zero bytes before writing, so whatever was in foobar.txt before is gone and replaced with the new content. This falls squarely under LPI objective 103.4, Streams, Pipes, and Redirects, which carries a weight of 4 on the 101-350 exam, so you should expect multiple questions touching this material. Option A with the double greater-than appends to the file instead of overwriting it, which is the single most common trap the exam writers use on this objective. Option B points the redirect the wrong direction entirely, feeding foobar.txt as stdin into echo, which echo ignores, and option D tries to use foobar.txt as if it were a command receiving a pipe, which will just give you a permission denied or command not found error. Memory hook: one arrow shoots through the file and kills what was there, two arrows add to the pile.

30
Thiago A.Thiago A.Jun 9, 2026

C, single right-angle bracket truncates and overwrites, double right-angle bracket appends, and I had to stop myself from second-guessing it on the actual exam because I kept staring at A thinking "well it does write to the file," but append is not overwrite and that distinction is exactly what they are testing.

5
Marit C.Marit C.Jun 12, 2026

The part that bites people in practice is forgetting that >> still creates the file if it does not exist, so the behavior is not purely additive, it is additive-or-create, and that edge case shows up in heredoc questions too.

0
Yusuf A.Yusuf A.Jun 12, 2026

C is the one because the single greater-than sign truncates whatever is already in foobar.txt and writes fresh, while the double greater-than in A just tacks the text onto the end, which is what my senior showed me when he was explaining why a log rotation script was bloating instead of resetting. Quick question though, if foobar.txt does not exist yet, does the single greater-than create it automatically or does it throw an error?

1
Carlos M.Carlos M.Jun 19, 2026

C is right - > overwrites, >> appends. Do you remember what < does here?

1
Marit C.Marit C.May 27, 2026

Saw this exact redirect operator question on my 101 sitting and I almost second-guessed myself because I kept mixing up > and >> under pressure, but I just remembered that > truncates and overwrites while >> appends, so C is the one that blows away whatever was in foobar.txt before writing. D is the trap if you forget that piping sends stdout to another command, not a file.

0
Devraj B.Devraj B.May 29, 2026

Good memory hook on the overwrite-versus-append split, and worth adding for the 102 crowd that set -o noclobber flips the behavior of > so it errors on an existing file, which means the exam can swap in >| as the only correct overwrite syntax and catch anyone who memorized just the basic pair.

0
Full 101-350 Practice