Linux Shell: "Cannot overwrite existing file" when the file is owned by you
If the shell
noclobber environment variable is set, you will not be able to overwrite a file's content by redirecting some output to it.
Code:
# echo "2nd Overwritten content">tmp.file
bash: tmp.file: cannot overwrite existing file
First option would be to disable the noclobber variable:Code:
# set +o noclobber; set -o | grep nocl
noclobber off
The second option is to use the pipe (|)right after the redirection sign:
Code:
# echo "2nd Overwritten content" >| tmp.file
# cat tmp.file
2nd Overwritten content