4

I'm trying to find all files with given extension but I'm getting this error:

tar: Cannot update compressed archives
Try 'tar --help' or 'tar --usage' for more information.
tar: Cannot update compressed archives
Try 'tar --help' or 'tar --usage' for more information.
tar: Cannot update compressed archives
Try 'tar --help' or 'tar --usage' for more information.
tar: Cannot update compressed archives
Try 'tar --help' or 'tar --usage' for more information.
tar: Cannot update compressed archives
Try 'tar --help' or 'tar --usage' for more information.
tar: Cannot update compressed archives
Try 'tar --help' or 'tar --usage' for more information.

Here is the script:

touch archive.tar.bz2; find . -type f \( -name '*.bak' -o -name '*.c' -o -name '~*' \) -exec tar rjvf archive.tar.bz2 {} \; -exec rm -rf {} \;

Is there any way how to update compressed archive using find?

Jeff Schaller
  • 66,199
  • 35
  • 114
  • 250
pnom
  • 297
  • 1
  • 3
  • 8

1 Answers1

5

No, you can't update a compressed archive using tar.

But, if your script is creating the archive (using touch), you can update it and compress it later. Change rjvf to rvf, and at the end of your script, run bzip2 archive.tar (I take it from the j option and your tags that you want to use bzip2 for compression).

Stephen Kitt
  • 411,918
  • 54
  • 1,065
  • 1,164