Suppose I have three files on disk as f1,f2,f3 and one folder testfolder. In my archive only f4,f5 files are present.

After an untar operation I want f1,f2,f3 files to be removed/deleted as they are not present in archive. At the same time some files/folders need to be excluded and only f4,f5 files with test folder should be there on the disk.

Is that possible? How would I do it?

  • Hello Aditi. What have you tried? – roaima Sep 20 '18 at 12:16
  • Remove the original files before extracting the archive. When you extract, exclude the file you don't want to extract. – Kusalananda Sep 20 '18 at 12:20

Suppose "tarfile.tar" is your tar archive, and "originaldir" is the directory where testfolder, f1, f2, f3 currently exist

$ mkdir untardir
$ ls
originaldir tarfile.tar untardir

$ tar -C untardir -xvf tarfile.tar
$ rsync -av originaldir/testfolder/ untardir/testfolder/
$ rsync --delete -av untardir/ originaldir/
$ rm -rf untardir

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.