Extracting specific files with file extension from a .tar.xz archive using MacOS terminal

纵然是瞬间 提交于 2020-04-16 04:05:53

问题


I have a number of compressed archives with the extension .tar.xz. I am advised that, when decompressed, the total size required is around 2TB.

Within the archives are a number of images that I am solely after.

Is there a method to solely extract files for example with the extensions .jpeg, .jpeg and .gif from the compressed archives without having to extract every file?

Thanks


回答1:


It's trivial to just extract one of the file types; for example:

tar -xjf archive.tar.xz '*.jpeg'

will extract all files with the .jpeg extension. It's important to quote the *, as otherwise the shell would attempt to expand it, and would only try to match only the files that were found (or fail because there were no files with that name).

You can similarly use other patterns like '*.gif', or both together:

tar -xjf archive.tar.xz '*.jpeg' '*.gif'

Because you tag that you're using OSX, I'll skip the need to use the --wildcards option, which is needed when trying to extract only those files under linux.



来源:https://stackoverflow.com/questions/40811165/extracting-specific-files-with-file-extension-from-a-tar-xz-archive-using-macos

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