Shell redirection operation> |?
>|
overrides an option noclobber
in the shell (set with $ set -o noclobber
, specifies that files cannot be written).
Basically, noclobber
an error pops up if you try to overwrite an existing file with >
:
$ ./program > existing_file.txt
bash: existing_file.txt: cannot overwrite existing file
$
Usage will >|
override this error and cause the file to write:
$ ./program >| existing_file.txt
$
It is similar to using options -f
or --force
for many shell commands.
In the Bash Reference Manual Section "3.6.2 Redirecting Output":
If the redirection operator
>
, and the optionnoclobber
for inline set is enabled, the redirection will fail if the file whose name is the result of the word extension exists and is a regular file. If a redirection operator>|
, or a redirection operator>
, and the parameter isnoclobber
not included, the redirection is performed even if the file named by the word exists.
Searching for "bash noclobber" usually brings up articles that mention this somewhere. See this question on SuperUser , this section on O'Reilly's "Unix Power Tools" , and this Wikipedia article on Clobbering for examples.
source to share