Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

I lost a couple hundred lines of a Vim plugin I wrote and continue back up every so often because I extracted a tar file containing an older version. I decided not to use source control management when I wrote the plugin, since I only update it periodically.

Why doesn't tar ask before overwriting existing files by default? I'm guessing that there's some rationale behind why the default behavior is to overwrite files silently, since we usually want safety over speed and convenience. For example, we usually use #ifdef NDEBUG, not #ifdef DEBUG; similarly, I would expect tar ask me before overwriting any files, and for it to have some flag which I can use to tell it to overwrite files without asking me. Also, how can make it so that tar does ask me by default, without me having to give it any flags? I'm fine with using tools other than tar, if they support this safer default behavior.

Thank you for your time!

share|improve this question
11  
"I decided not to use source control management..." Well, there's your first problem. –  cjm Feb 22 '12 at 5:29
    
It seems kind of silly to use SCM for every little project that I ever decide to do. Isn't it sort of overkill? I suppose that if it saves me from accidentally losing files, then it's a good tradeoff. –  void-pointer Feb 22 '12 at 6:47
    
For little things (such as config files), I like rcs. It is a far cry from things like git or even cvs, but it does the basic stuff (i.e. keep a versioned history). –  Ansgar Esztermann Feb 22 '12 at 9:41
1  
@void-pointer SCM is overkill for a single file that will never ever change. For anything else, it's appropriate. –  Gilles Feb 23 '12 at 2:33
1  
git gives you the convenience of rcs (no need to worry about setting up a remote repository; just work where you are) with modern features and the ability to scale up if you decide to. If you already know the basics, there's basically no extra overhead for using it for "every little project". –  mattdm Mar 8 '12 at 3:16
show 1 more comment

2 Answers

up vote 8 down vote accepted

The same reason rm, cp and a whole slew of other utilities don't -- from early on, the POSIX design concept has always been to assume that the person at the console knows what they're doing and not to ask for clarification unless there's an actual problem.

In the case of tar, a look at the manual page suggests you could try setting the TAR_OPTIONS env variable to include the --confirmation flag.

share|improve this answer
3  
Unfortunately, --confirmation is a little too safe. It asks before extracting every file, whether or not it already exists. Worse, it doesn't tell you if the file already exists. –  cjm Feb 22 '12 at 6:14
1  
Maybe alternatives like --keep-newer-files, --keep-old-files can be used instead? –  Bernhard Feb 22 '12 at 7:41
add comment

tar -k option asks for a confirmation if the file already exists. You could set it by default either by adding it to the TAR_OPTIONS variable (TAR_OPTIONS="$TAR_OPTIONS -k") or creating an alias (alias tar="tar -k").

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.