Warm tip: This article is reproduced from serverfault.com, please click

How do I delete a single file from a tar.gz archive

发布于 2015-06-21 08:12:11

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

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

tar: Option --delete is not supported

Is there a way to:

  1. remove the file from the archive without unzipping it?
  2. extract the archive but exclude the file?
Questioner
KillerDesigner
Viewed
0
msfoster 2015-06-21 16:33:44

As mentioned in the comments it's not possible to remove the file using tar, but you can exclude the file when extracting:

tar -zxvf file.tar.gz --exclude "file_to_exclude"