Ask Ubuntu is a question and answer site for Ubuntu users and developers. 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

Is there a way to tar extract without clobbering?

I am installing 12.04 and want to restore my data from 10.10. Anything 12.04 specific I would like to keep, that is I do not want the tar'd 10.10 version to be extracted. If I do a general restore such files as .bashrc will be clobbered. Is there a way to avoid this?

Edit: I would note that a booted 12.04 ISO disk image allows an upgrade from 10.10 (or whatever) and it offers to keep old data. I tried this but it complained some applications might be left broken after the upgrade. I decided to just reboot and do a clean install.

share|improve this question
up vote 9 down vote accepted

I have difficulty understanding what you want but if you made a tar file of your whole system I believe you made a very large tar file that has not a real purpose unless you completely restore the tar file. If you wanted to save your own documents you should have made a backup of those documents and nothing else.

After saying that tar has several nifty options ...


This will not overwrite existing files.


This will keep all files that have a newer timestamp as is.


This will leave the metadata of an existing directory as is.

A manual for tar can be found here.

But I would advice extracting the tar file on another medium and manually restore those files. It is the safest method.

share|improve this answer
Even with --keep-newer-files and --no-overwrite-dir, extracting an old full system backup onto a new system will leave your system in a goofed up state since many files that shouldn't be there will be extracted. You should just open the archive in the gui with file-roller and extract the specific files you want to your home directory. – psusi Apr 30 '12 at 13:37
I agree as per my last line in my answer :) – Rinzwind Apr 30 '12 at 13:48
@Rinzwind, you are right, my archive has a faulty design. Many exclusions and still not enough exclusions so it's a mess and dangerous to restore since it would be Maverick overwriting onto Precise. My next archive will be strictly inclusions. Your suggestion about manual restoration is a good one. – H2ONaCl May 4 '12 at 7:19

From tar(1):

 -k, --keep-old-files
       don't replace existing files when extracting

Seems clear to me. If files in the tarball are stored relatively to your old homedir:

tar xvkf backup.tar.gz -C ~
share|improve this answer

Your Answer


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.