将焦油提取物导入焦油中 [英] pipe tar extract into tar create

查看:122
本文介绍了将焦油提取物导入焦油中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我现在有一个tar.gz,我只想从其中提取一个或两个文件,然后一次性打包/添加到新的tar.gz中.当然,我可以将其保存到一个临时文件中并使用它,但是绝对要求是在没有任何中间文件输出(即管道)的情况下完成所有操作.换句话说,我想要的是类似以下的伪代码(显然语法不正确)

I have a tar.gz right now, and I want to extract just a file or two from it, and pack/add those into a new tar.gz, all in one go. Of course I can just save to a temporary file and work with it, but the ABSOLUTE requirement is to do this all without having any intermediate file output, i.e. piping. In other words, what I would like is something like the following pseudo-code (obviously the syntax is incorrect)

tar -xvf first.tar.gz subdir1/file1 subdir2/file2 | tar cf - | gzip > second.tar.gz

有人知道正确的语法吗?我尝试了许多变体,但无济于事.

Does anyone know the proper syntax for this? I have tried many variants, but to no avail.

我对使用cpio的想法也很开放,但是同样,我对如何正确地降低语法感到困惑,从我的理解来看,cpio仅吸收档案或文件名,而不吸收文件.

I am also very open to the idea of using cpio, but again, I am stumped by how to get the syntax down properly, and from what I understand, cpio intakes only archives or filenames, not files.

任何帮助将不胜感激.

压缩包中没有要提取的特定文件名模式.鉴于BSD和GNU tar一次只能搜索一个模式,因此我不确定是否可以分别使用include/exclude标志.

There is no particular filename pattern inside the tarball to extract. Given that the BSD and GNU tar can only search one pattern at a time, I'm not sure if it's even possible to use the include/exclude flags, respectively.

推荐答案

我假设您正在使用或可以得到 GNU tar .

I am assuming that you are using or that you can get GNU tar.

您可以使用--delete选项将一个tar文件处理为另一个.例如:

You can use the --delete option to process one tar file to another. E.g.:

% tar cf x.tar a b c d
% tar tf x.tar
a
b
c
d
% cat x.tar | tar f - --delete b c > y.tar
% tar tf y.tar
a
d
%

请注意,您可以指定要删除的多个名称.然后,您只需要弄清楚如何在命令行上指定要删除的所有文件,而不是要保留的文件即可.

Note that you can specify multiple names to delete. Then you just need to figure out how specify all the files to get rid of on the command line, instead of the files to keep.

这篇关于将焦油提取物导入焦油中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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