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

Answer

> is the overwrite redirect operator. It creates the file if it doesn't exist, or truncates it to zero bytes before writing. This is destructive — existing content is lost. >> is the append redirect operator. It creates the file if it doesn't exist, or adds new content to the end of an existing file without destroying current content. Example: echo "start" > log.txt creates/overwrites; echo "more" >> log.txt appends. In scripts, use >> for logging to avoid accidentally wiping log files. Use : > file or truncate -s 0 file to explicitly empty a file.