1

I want to append files to foo.tar:

tar -rvf foo.tar IMG_1807.MOV

this works, but when I want to remove files:

tar -dvf foo.tar IMG_1807.MOV

doesn't work. It shows the output:

Terminal:~/Desktop$ tar -dvf foo.tar IMG_1807.MOV 
IMG_1807.MOV
Terminal:~/Desktop$ tar -tvf foo.tar
-rw-rw-r-- user/user    33084363 2018-12-19 03:02 IMG_1807.MOV

but doesn't delete anything. What should I do?

Second, how can I add or remove files from file.tar.gz or file.tar.bz2 or file.tar.xz? Is there any command or I should always untar and tar again?


Edit:

Third: How to extract a specific file from a zipped file? Or how to extract from tar in a specific location? This did NOT work:

 tar -xvf foo.tar IMG_1807.MOV -C /path/to/destination

1 Answers1

5

-d is not delete but diff.

From man tar:

 -d, --diff, --compare
       find differences between archive and file system

use --delete.

tar --delete -vf foo.tar IMG_1807.MOV

You cannot update a tar.gz file, see this and this.


Regarding your question how to extract to specific location:

You must follow the correct command line order. -C as an option goes before [pathname]. See man tar for more information. The following works:

tar -xvf foo.tar -C /path/to/destination IMG_1807.MOV
pLumo
  • 26,947