使用MacOS终端从.tar.xz存档中提取带有文件扩展名的特定文件 [英] Extracting specific files with file extension from a .tar.xz archive using MacOS terminal

查看:71
本文介绍了使用MacOS终端从.tar.xz存档中提取带有文件扩展名的特定文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有许多压缩档案,扩展名为 .tar.xz .我建议解压缩后所需的总大小约为2TB.

在存档中有很多我只想要的图像.

是否有一种方法可以从压缩档案中仅提取扩展名为 .jpeg,.jpeg .gif 的文件,而不必提取每个文件?

谢谢

解决方案

仅提取一种文件类型是很简单的.例如:

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

将提取所有扩展名为 .jpeg 的文件.引用 * 很重要,否则shell会尝试对其进行扩展,并且只会尝试仅匹配找到的文件(否则将失败,因为没有该名称的文件)./p>

您可以类似地使用"* .gif"之类的其他模式,或同时使用这两种模式:

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

因为您标记了您正在使用OSX,所以我将跳过使用-wildcards 选项的需要,该选项在尝试仅在Linux下提取那些文件时是必需的.

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

解决方案

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.

这篇关于使用MacOS终端从.tar.xz存档中提取带有文件扩展名的特定文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆