Ubuntu – What’s is the difference between “>” and “>>” in shell command

command line

Could someone explain to me the difference between > and >> when using shell commands?

Example:

ps -aux > log
ps -aux >> log

It seems the result is the same either way.

Best Answer

> is used to overwrite (“clobber”) a file and >> is used to append to a file.

Thus, when you use ps aux > file, the output of ps aux will be written to file and if a file named file was already present, its contents will be overwritten.

And if you use ps aux >> file, the output of ps aux will be written to file and if the file named file was already present, the file will now contain its previous contents and also the contents of ps aux, written after its older contents of file.