> and >>
What is > and >>?
> and >>: Redirect output — > overwrites a file with output. >> appends to a file. The > and >> operators send a command's output to a file instead of the screen. echo hello > notes.txt creates the file or overwrites it. echo world >> notes.txt adds a line to the end.
Frequently asked questions about > and >>
How is > and >> used in practice?
The difference is easy to forget and costly to get wrong. A single > on an existing log or config file wipes its contents before the command even runs. Many shells offer set -o noclobber to stop > from overwriting files by accident.
What should you keep in mind with > and >>?
These operators only capture normal output. Error messages go to a separate stream, so command > out.txt still prints errors to the screen. Use 2> for errors, or > out.txt 2>&1 to send both to the same file. In cron jobs, redirecting both is the easiest way to find out later why a job failed at three in the morning.
At a glance
| Category | CLI commands |
|---|---|
| Explained by | Reinier de la Parra |
| Updated |