Ubuntu – Extracting from a tar file – Default behavior: overwrite or keep

bash

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
           overwrite existing files when extracting

which one is used by default?

Best Answer

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 ?
1
2

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.