Connect commands

INPUT · Slides

Add without wiping (`>>`)

01 / 06

> wipes. So there is >>

In the last lesson you saw that > overwrites in silence. That makes it useless for a file you want to pile things onto, like a diary or a log.

The way to write that is >>. Just two arrows instead of one.

echo Jan 20 ramen >> diary.txt

What is already there stays, and the new line goes on the bottom.

~ $ cat diary.txtJan 5 startedJan 8 kept going~ $ echo Jan 20 ramen >> diary.txt~ $ cat diary.txtJan 5 startedJan 8 kept goingJan 20 ramen

02 / 06

That is the whole difference

How you write itWhen it is not thereWhen it is
>makes itwipes it and writes
>>makes itadds at the bottom

When the file is not there they behave the same. The only difference is when there is something in it already.

When in doubt, >> is the safer one. Adding too much can be fixed; what has gone does not come back.

03 / 06

You can add from any tool

Like >, the command knows nothing about >>, so it works with anything.

date >> record.txt        # add the timels >> record.txt          # add a listingwc -l names.txt >> record.txt   # add a countcat other.txt >> record.txt     # add another file's contents

This is how you gather records into a single file.

That is all a log really is. What a program does amounts to the same thing.

04 / 06

date puts the time down

A record needs when it happened, and date is what gives you that.

date

Type it and the date and time come out on one line. Add that with >> and you have a record of when you did what.

The clock in this learning environment runs on universal time (UTC), so it is nine hours off Japanese time. Nothing to worry about, but that is why the time may look wrong.

~ $ dateFri Aug 21 06:49:10 UTC 2026

05 / 06

With >> even the file itself is survivable

Pointing > at the same file wiped it. What about >>?

cat f.txt >> f.txt

This does not wipe it (it only adds, so nothing gets emptied first). But do not do it anyway. It reads while it adds, and if you are unlucky the same lines go on multiplying forever.

"Read a file while writing to it" is the wrong move with > and with >> alike. Write to another name and swap them over is the safe shape.

06 / 06

Now have a go

diary.txt holds two lines of diary and record.txt holds a one line heading.

You will be typing the same >> again and again in this lesson. But the command in front of it changes each time: echo, date, ls, wc, cat, find, grep.

What to take away is that anything at all can go on the left of >>. Once you have that, this lesson is done.