# Untar with exclusions of existing folder and delete files on disk which are not present in disk

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

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