Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free.

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

In the documentation, I read that tar has the following options when extracting files from a tarball:

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

which one is used by default?

share|improve this question
up vote 13 down vote accepted

You can try it by yourself:

echo 1 > 1
echo 2 > 2
tar cf foo.tar 1 2
echo 3 > 1
echo 4 > 2
tar xf foo.tar
cat ?

First two files (1 and 2) were created. Than an archive foo.tar was created. The next step changed the file contents and after that foo.tar was extracted. If you look into the files you'll see the old contents.

So --overwrite is default.

share|improve this answer
Thanks @qbi. Interestingly my intuition was wrong. – Amelio Vazquez-Reina Apr 27 '11 at 13:04
the default is: --overwrite-dir overwrite metadata of existing directories when extracting (default) – janwen Oct 8 '13 at 7:35
And an explanation of the behavior:… – ernie Mar 4 '15 at 19:37

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.