Frequently Asked Question

What is the difference between > and >> in shell redirection?

Both operators send standard output to a file, but with very different policies for the file's existing contents. > truncates: it opens the file with the O_TRUNC flag, throwing away anything that was already there before the new data starts arriving. If the file doesn't exist it's created; if it does exist it's silently wiped. There is no warning, no prompt, and no recovery.

>> appends: it opens the file with O_APPEND, which seeks to the end before every write. Previous contents are preserved and new bytes go after them. This is the right operator for log files and anything you want to accumulate across runs. The asymmetry between the two has cost more than one person an afternoon's work, so most experienced shell users develop a strong habit of pausing before typing a single >.

Further reading and video