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.


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.

  • 4
    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
  • 2
    @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 ~
  • does this also work while compressing. – nyxee Aug 16 '17 at 18:36
  • @nyxee It also works when trying to extract a compressed archive (e.g. tar xvkzf backup.tar.gz -C ~). I don't think it is recognized when you try to create a new archvie (tar czf foo.tar.gz foo/) if you are asking about that. – Lekensteyn Aug 18 '17 at 7:18

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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