Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

The bash noclobber option prevents one from overwriting files with redirection. But sometimes I really want to. csh has a similar option and it can be over-ridden by putting a ! before the filenames. Is there any way to do this with bash?

share|improve this question
up vote 17 down vote accepted

Yes. Append | to the redirection operator to form >|. This is in § 3.6.2 of the Bash Reference Manual, q.v.

If the redirection operator is ‘>’, and the noclobber option to the set builtin has been enabled, the redirection will fail if the file whose name results from the expansion of word exists and is a regular file. If the redirection operator is ‘>|’, or the redirection operator is ‘>’ and the noclobber option is not enabled, the redirection is attempted even if the file named by word exists.

Visit this tutorial about the noclobber option. It might be of help.

share|improve this answer
Thanks! I wish they had used the same syntax... – vy32 Nov 6 '11 at 12:32

Use | ("pipe") in bash, instead of ! ("bang") as you would in csh. For example:

echo done >| out

Note that if you want to redirect stderr to stdout and override noclobber, neither >|& nor &>| will work; use the long form instead:

cmd-with-errors done >| out 2>&1
share|improve this answer
Do you know why err &>| out doesn't work? – Hugh Lee Oct 23 '13 at 13:39

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .