Search This Blog

Tuesday, January 28, 2014

Significance of noclobber

noclobber: Protecting files from accidental overwriting. This feature is known as noclobber. Once set, you can protect your files from being overwritten with the shell's > and >> symbols.

This particular option is designed to keep you from accidentally destroying your existing files by redirecting input over an already-existing file.

set noclobber #No more overwriting files with >

If you now redirect command output to an existing file foo, the shell will retort with a message:

foo: File exists.

To override this protection feature, you have to use the ! after the >:

head -5 emp.lst >! foo

To find out the different settings:

set -o

To unset the "noclobber" option:

set +o noclobber

No comments:

Post a Comment