sourcecode

Thursday, July 5, 2012

Append v.s. Overwrite

http://forum.ivorde.ro/linux-shell-protecting-against-accidental-output-redirection-and-file-overwrite-t26.html

When redirecting the output, using > overwrites an existing file and using >> to append to an existing file.

When I was recording the output of a series of command to a single file, I started to worry about that I could type > instead of >> by mistake and accidentally erase all the hard work I had done.

Here is the save: disable the ability to overwrite a file by setting noclobber:
$set -o
shows
noclobber    off
then
$set -o noclobber
TA-DA, files can not be overwritten anymore. I personally like this setting. If I really want to overwrite a file, I would rm it first, then create a new one.



From Starship Troopers:
http://en.wikiquote.org/wiki/Starship_Troopers_%28film%29

Ace Levy: Sir, I don't understand. What good's a knife in a nuke fight? All you have to do is press a button, sir.
Career Sergeant Zim: Put your hand on that wall, trooper. [Ace hesitates] PUT YOUR HAND ON THAT WALL! [Zim throws a knife and hits Ace's hand, pinning it to the wall] The enemy cannot press a button... if you have disabled his hand. Medic!
/***************END******************/

No comments: