How to delete one file from tar.gz archive

I have a huge tarbell archive with an excessively large or damaged error_log that causes the archive to freeze when trying to extract it. Is there a way to remove this from the archive before unpacking or extracting the archive without extracting that specific file on a Mac OS X terminal?

I found this post about how efficiently-remove-files-from-large-tgz , however I tried the -delete flag but got this error:

tar: Option --delete is not supported 

Is there any way:

  • delete a file from the archive without unzipping it?
  • extract archive but exclude file?
+12
source share
3 answers

As mentioned in the comments, it is not possible to delete the file using tar, but you can exclude the file when you extract:

 tar -zxvf file.tar.gz --exclude "file_to_exclude" 
+15
source

You can pack it like this:

 tar -czvf ./new.tar.gz --exclude='._*' @old.tar.gz 

I used ._* to delete all ._files , but you can use any template you like, including the full path, directory, file name, or whatever.

0
source

Dear, you can delete the archive file in the same format in which we delete the directory from below using the command through

command: - rm -rf archive file name r: - recursively

-2
source

Source: https://habr.com/ru/post/989467/


All Articles