【发布时间】:2015-10-05 09:08:57
【问题描述】:
我有一个压缩命令,我将它传送到一个 md5sum 检查命令:
tar zcvpf file.tar.gz file | xargs -I '{}' bash -c "test -f '{}' && md5sum '{}'" | tee file_mybackup.md5
我现在想将 tar.gz 文件拆分为 100MB 的块。我可以这样做:
tar zcvpf - file | split -d -b 1M - file.tar.gz.
有没有一种方法可以将 tar 命令的输出通过管道传输到同时执行 split 命令和 md5sum 检查?我知道 split 不会输出到 STDOUT 所以我不能从 split 命令到 md5sum 命令。 我尝试使用命名管道:
mkfifo newpipe
tar zcvpf - file | tee newpipe | split -d -b 1M - file.tar.gz. &
cat newpipe | xargs -I '{}' bash -c "test -f '{}' && md5sum '{}'" | tee file_mybackup.md5
但是,这无法输出 md5sum 输出。任何帮助将不胜感激
【问题讨论】:
-
command | tee >(command 2) | command 3 -
你对
xargs的使用被破坏了:你的代码被任意代码执行! -
好的,使用@999999999999999999999999999999 的方法:
tar zcvpf - file | tee >(xargs -I '{}' bash -c "test -f '{}' && md5sum '{}'" > file.md5) | split -d -b 1M - file.tar.gz.但是这会产生错误xargs: Warning: a NUL character occurred in the input. It cannot be passed through in the argument list. Did you mean to use the --null option?如何将 STDOUT 重定向到 xargs -I 命令?