Appending: >>
You learned that > overwrites a file. When you want to add new lines at the end
without destroying existing content, use >> (double arrow).
The pattern is: COMMAND >> FILE.
echo "Entry 1: docking complete" >> ship.log
echo "Entry 2: cargo loaded" >> ship.log
cat ship.log
Entry 1: docking complete
Entry 2: cargo loaded
Both lines are preserved. Each >> appends to the bottom.
> vs >>
| Operator | Behavior |
|---|---|
> | Create / overwrite |
>> | Create / append |
If the file does not exist yet, both > and >> will create it. The difference
only matters when the file already has content.
A common pattern is to use > once to start fresh, then >> to accumulate more data
over time, like a station log that grows with each shift.
Mission: Shift Log Update
The outgoing watch officer recorded the launch sequence in mission.log. Your shift is starting and you need to update the record, then file a backup.
- Add
status: shields nominalto the end ofmission.logwithout erasing the existing entry. - Add
status: crew readyto the end ofmission.logthe same way. - Count the lines in
mission.logto confirm it now holds three entries. - Create a folder called
archiveand copymission.loginto it under the namemission-backup.log.
Expected result
mission.log holds all three status lines, and archive/mission-backup.log is an identical backup:
status: launch sequence initiated
status: shields nominal
status: crew ready