>/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/null via either redirect > or append >> is identical. A quick test shows that it also makes no difference timing wise:
Content to print:
for i in range(10**4):
print("content")
Test time command:
time python printlots.py >> /dev/null ; time python printlots.py > /dev/null
Result:
$ time python printlots.py >> /dev/null ; time python printlots.py > /dev/null
real 0m0.094s
user 0m0.047s
sys 0m0.047s
real 0m0.096s
user 0m0.031s
sys 0m0.063s
So it won't make a measureable difference which you use. It seems the reason both work is to enable developers to use /dev/null in 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/null would mean you'd have to check first what the target file is. At least that's what this answer assumes.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With