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

时光怂恿深爱的人放手 提交于 2019-12-06 17:55:07

问题


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?

回答1:


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"



回答2:


You can repackage it like this:

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

I used ._* to remove all ._files, but you can use any pattern you like, including a full path, directory, filename, or whatever.




回答3:


Dear you can delete the archive file through the same format as we remove the directory from below command through

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



来源:https://stackoverflow.com/questions/30962501/how-do-i-delete-a-single-file-from-a-tar-gz-archive

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!