4

我正在尝试使用 pv 提取大型 .tar 文件。

pv large_file.tar.gz | tar -xcf /../MyFolder.

pv 命令按预期工作,在控制台中显示进度。

我正在尝试拆分标准输出,以在控制台中显示进度并将相同的突出显示保存到文件中。

我尝试用 tee 这样做,但无法使其工作。

pv large_file.tar.gz | tee /tmp/strout.log | tar -xcf /../MyFolder

有什么建议我如何将进度显示到控制台并同时将其保存到文件中?

谢谢!

4

2 回答 2

3

不确定您的原始命令是否有效,因为 tar 的选项中有几个错误。

鉴于../MyFolder存在,您的第一个命令需要是

    pv large_file.tar.gz | tar -xz -C ../MyFolder

如果您在pv和调用之间插入 tee 调用tar,那么整个链条都会起作用。

    pv large_file.tar.gz | tee /tmp/strout.log | tar -xz -C ../MyFolder

但是我不确定它是否符合您的期望。如果您将 pv 输出通过管道传输到 tee,则 tee 会将其通过管道传输到 tar,并将与原始 tar 相同的内容转储到 /tmp/strout.log,从而将您的 tar 提取../MyFolder并复制到 /tmp/strout.log。

编辑
正如@DownloadPizza 所建议的,您可以使用进程替换(请参阅How do I write stderr to a file while using "tee" with a pipe?)。通过使用-fpv 标志,您的命令将变为

    pv -f large_file.tar.gz 2> >(tee /tmp/strout.log) > >(tar -xz -C ../MyFolder)

并将产生预期的输出。

于 2020-02-20T08:26:51.797 回答
2

PV progress is sent to stderr, can you try this?: pv large_file.tar.gz > >(tar -xz -C ./MyFolder/) | echo you might need to edit the tar command as i couldnt get yours to work for me

于 2020-02-20T07:46:29.220 回答