> empties the file first. To add to a file, use >>. It writes after the last line, and the old text stays.
| The file does not exist | The file exists | |
|---|---|---|
> | Makes it | Empties it, then writes |
>> | Makes it | Writes after the last line |
mon: anawas in the file
tue: benadded at the end
text
learner@tidepool:~$ cat rota.txt
mon: ana
learner@tidepool:~$ echo "tue: ben" >> rota.txt
learner@tidepool:~$ cat rota.txt
mon: ana
tue: benCollect output from more than one command
Make a report from several commands. Use > for the first command, then >> for each command after it:
text
learner@tidepool:~$ grep ERROR till.log > ~/reports/errors.txt
learner@tidepool:~$ grep ERROR web.log >> ~/reports/errors.txtThe first > empties the file, so that nothing from yesterday stays in the report.