Does tar -xvf remove existing files from directory?

Solution 1:

Duplicate files that already exist may or may not be unpacked and overwritten depending on your system. However, it usually does by default. Files that are in the archive but not on your system will simply be added to new or existing directories on your system.

Dir /test

/1/a
c

Archive test.tar

/1/b
d

will probably be merged to:

/1/a
/1/b
c
d

Adding the -k flag to the tar command will make sure none of the files on your target directory will be overwritten:

tar -xvkf test.tar