Lessons · Terminal · >> (add to the end)
Adding to a file
command >> file adds the output to the end of the file and keeps everything that was there.
Hone is a place to practise programming. This is one of its lessons, written out in full and free to read without an account.
What it is for
A running log, a list you build up over time, a note appended by a script each night: all of them need the arrow that never loses the past.
How to think about it
Use >> whenever the file already means something. Use > only when you intend to start over.
Worked example
echo one > list.txtStart the list.
echo two >> list.txtAdd to it.
cat list.txtone, two: both lines.
Your turn
Add a line to the end of notes.txt.
echo 'done' notes.txt
Try it at a real prompt
The trap
Typing > when you meant >>. The whole list is gone, and no command brings it back.
Practise >> (add to the end) on HoneA question on it now, a coding challenge where there is one, and it is remembered for review. Free, no email needed.