Clobbering the files will  helps in keeping the files safe from Accidental over writing. It can be too easy to mistype a filename and find that you’ve redirected output into a file that you meant to save.

To be on safer side you can set clobber for your important files using the bellow command.

————–
$ set -o noclobber

————–

If you decide you don’t want to be so careful after all, then turn the option off:

 ————–
 $ set +o noclobber
 ————–

Example:
————-
vinoth.sk@3wing18:~$ set -o noclobber
vinoth.sk@3wing18:~$ echo b >a
-bash: a: cannot overwrite existing file
vinoth.sk@3wing18:~$ set +o noclobber
vinoth.sk@3wing18:~$ echo b >a
vinoth.sk@3wing18:~$
————-

Clobbering a File on Purpose
Use >| to redirect your output. Even if noclobber is set, bash ignores its setting and overwrites the file.

————

$ echo something > my.file
$ set -o noclobber
$ echo some more >| my.file
$ cat my.file
———-

Leave a Reply