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.

"I decided not to use source control management..." Well, there's your first problem.
–
cjmFeb 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-pointerFeb 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 EsztermannFeb 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.
–
GillesFeb 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".
–
mattdmMar 8 '12 at 3:16

2 Answers
2

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.

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.
–
cjmFeb 22 '12 at 6:14

1

Maybe alternatives like --keep-newer-files, --keep-old-files can be used instead?
–
BernhardFeb 22 '12 at 7:41

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").