What is the difference between the following two redirection commands?

ls > out
ls >| out

They both seem to produce the same output.


According to [1] the difference is that >| redirects the output to a file even if noclobber option is set.

noclobber option is set by bash's command line option -C and prevents overwriting of files by redirection [2]. When the noclobber option is set, then ls >| out overwrittes the file out, while ls > out does not.

[1] http://tldp.org/LDP/abs/html/special-chars.html
[2] http://tldp.org/LDP/abs/html/options.html#NOCLOBBERREF

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.