Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Pretty noob move but used tar with the source and destination file arguments swapped resulting in a complete mess (the source file has been overwritten with another file of same name with size 4kb).

Is there any way to recover my original file?

As an aside, I'm surprised the default is to overwrite but I suppose I shouldn't be doing something like this before my morning coffee. Ugh.

share|improve this question

Unless you have a backup of the original source file stored elsewhere, you are unfortunately out of luck. Tar has no way of recovering from this particular error condition.

share|improve this answer

Maybe this could be an inspiring moment to write a script. Rename the tar command as tar.orig, and name your new script Have your new script:

  1. perform a sanity check as to which is input and which is output (check .ext? filesize? date-time stamp?), then
  2. create a backup of your input file (cp input.bkp) before any processing is done.

You could also include a small piece of menu, configured to easily select between your favorite tar command option sets!

If you're feeling truly robust, you could also have your script rotate several backup files of each of your most recent 'runs' (using /tmp dir; .bkp, .bk4, .bk3, .bk2, .bk1), just in case you manage a good bit of keyboard-madness before that first cup-o-joe! Maybe also rotate a small log file as /var/log/my-tar.log to track date & time stamps and exact script-processed command line of what was executed during each of the last several 'runs' of your customized script!

For help with writing the script, bite the bullet and go the educational route: grab yourself an online PDF of "Advanced Bash-Scripting Guide" from The Linux Documentation Project. You'll be worlds ahead of the rest by spending the time to learn how to handle many script-needy situations - before they bite you from behind!

share|improve this answer

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .