tar: Dealing with Old Files

1 
1 Options Controlling the Overwriting of Existing Files
1 .....................................................
1 
1 When extracting files, if 'tar' discovers that the extracted file
1 already exists, it normally replaces the file by removing it before
1 extracting it, to prevent confusion in the presence of hard or symbolic
1 links.  (If the existing file is a symbolic link, it is removed, not
1 followed.)  However, if a directory cannot be removed because it is
1 nonempty, 'tar' normally overwrites its metadata (ownership, permission,
1 etc.).  The '--overwrite-dir' option enables this default behavior.  To
1 be more cautious and preserve the metadata of such a directory, use the
1 '--no-overwrite-dir' option.
1 
1    To be even more cautious and prevent existing files from being
1 replaced, use the '--keep-old-files' ('-k') option.  It causes 'tar' to
1 refuse to replace or update a file that already exists, i.e., a file
1 with the same name as an archive member prevents extraction of that
1 archive member.  Instead, it reports an error.  For example:
1 
1      $ ls
1      blues
1      $ tar -x -k -f archive.tar
1      tar: blues: Cannot open: File exists
1      tar: Exiting with failure status due to previous errors
1 
1    If you wish to preserve old files untouched, but don't want 'tar' to
1 treat them as errors, use the '--skip-old-files' option.  This option
1 causes 'tar' to silently skip extracting over existing files.
1 
1    To be more aggressive about altering existing files, use the
1 '--overwrite' option.  It causes 'tar' to overwrite existing files and
1 to follow existing symbolic links when extracting.
1 
1    Some people argue that GNU 'tar' should not hesitate to overwrite
1 files with other files when extracting.  When extracting a 'tar'
1 archive, they expect to see a faithful copy of the state of the file
1 system when the archive was created.  It is debatable that this would
1 always be a proper behavior.  For example, suppose one has an archive in
1 which 'usr/local' is a link to 'usr/local2'.  Since then, maybe the site
1 removed the link and renamed the whole hierarchy from '/usr/local2' to
1 '/usr/local'.  Such things happen all the time.  I guess it would not be
1 welcome at all that GNU 'tar' removes the whole hierarchy just to make
1 room for the link to be reinstated (unless it _also_ simultaneously
1 restores the full '/usr/local2', of course!)  GNU 'tar' is indeed able
1 to remove a whole hierarchy to reestablish a symbolic link, for example,
1 but _only if_ '--recursive-unlink' is specified to allow this behavior.
1 In any case, single files are silently removed.
1 
1    Finally, the '--unlink-first' ('-U') option can improve performance
1 in some cases by causing 'tar' to remove files unconditionally before
1 extracting them.
1