-3

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?

2
  • Hello Aditi. What have you tried? Sep 20, 2018 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, 2018 at 12:20

1 Answer 1

0

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

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .