11

I have a tar archive and I want to use tar -xvf.
In this tar archive I have a directory tree containing a couple of files. On my solaris 10 system this directory tree already exists and has several files in it.
If i unpack the archive is the entire directory tree overwritten or are only the files contained in the archive overwritten?
Will the files that do not have a correspondent in he archive get deleted?

Felicia
  • 113

2 Answers2

7

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
Pylsa
  • 31,383
0

Easiest way is to make a new, empty directory, cd to it, and extract the files there. You need to be careful though that the extracted files are relative (begin with ./) and not absolute (begin with /). Pipe the table of contents through less to see which is the case if you don't know (tar -tvf tar_filename | less)

You can find out if your tar version overwrites by default or not by looking at the man page. Tar will not delete files during extraction, which is another reason people usually start from a new, empty directory before doing the extract.

hotei
  • 3,693
  • 2
  • 21
  • 24