>/dev/null or >>/dev/null?
I understand the difference when writing (to) a regular file. But when it comes to /dev/null? Comments? Advices?
Redirecting or appending to /dev/null
965 Views Asked by useful At
1
>/dev/null or >>/dev/null?
I understand the difference when writing (to) a regular file. But when it comes to /dev/null? Comments? Advices?
It seems the behaviour for redirecting to
/dev/nullvia either redirect>or append>>is identical. A quick test shows that it also makes no difference timing wise:Content to print:
Test time command:
Result:
So it won't make a measureable difference which you use. It seems the reason both work is to enable developers to use
/dev/nullin their code with more flexibility. If you have a program where one input parameter is the output file it prints to, and append is your default mode, not having append to/dev/nullwould mean you'd have to check first what the target file is. At least that's what this answer assumes.