Linux, FreeBSD, Juniper, Cisco / Network security articles and troubleshooting guides
https://forum.ivorde.com/

Linux Shell: "Cannot overwrite existing file" when the file is owned by you
https://forum.ivorde.com/linux-shell-cannot-overwrite-existing-file-when-the-file-is-owned-by-you-t27.html
Page 1 of 1

Author:  LaR3 [ Mon Aug 24, 2009 10:26 am ]
Post subject:  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

Page 1 of 1 All times are UTC - 5 hours [ DST ]
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
http://www.phpbb.com/