Quiz Entry - updated: 2026.07.14
How do you append output to a file instead of overwriting it?
Use >> instead of > — it adds output to the end of the file, keeping what's already there.
echo "First line" > file.txt # > truncates: file now holds just this line
echo "Second line" >> file.txt # >> appends: file now holds both lines
| Operator | Effect on an existing file |
|---|---|
> |
wipes it first, then writes |
>> |
leaves it intact, writes at the end |
The single vs. double > is the difference between replace and add. It's a one-character mistake with big consequences: > on your logfile silently erases the entire history. Reach for >> whenever a file should accumulate over time — logs, audit trails, or output gathered from many commands in a script.
date >> log.txt
echo "Backup started" >> log.txt # each run grows the log instead of resetting it
Tip: 2>> is the stderr equivalent — append errors to an error log without overwriting.