0

I am using tar -xf archive.tar -C /home/user/target/folder (in a bash script) to extract the contents of a specific archive (archive.tar) into the target directory (/home/user/target/folder) so that all existing contents of the target directory will be overwritten by the new ones (contained in the archive).

All works great, but it is one directory in the archive that I would like to omit (from extracting and thus overwriting the existing one in the target folder)... For example, if the archive.tar contains:

folderA/
folderB/
folderC/
folderD/
fileA.php
fileB.php
fileC.xml

How could I extract (and overwrite) all EXCEPT (for example) folderC/ ??

tar --version outputs tar (GNU tar) 1.23

MadHatter
  • 79,770
  • 20
  • 184
  • 232
Theo Orphanos
  • 133
  • 1
  • 10

1 Answers1

2

Use the -X option or the --exclude option

filename is the name of a file with a list of patterns you want to exclude. pattern is a single pattern you want to exclude.

To exclude FolderC use the command below

tar -xf archive.tar --exclude folderC -C /home/user/target/folder

Use man tar on your sytem for a full explanation of the two options.