即时解压缩大量文件
我有一个脚本,需要在扩展名为 **.tar.gz* 的大量文件上运行。
我希望能够在运行命令时解压缩它们,然后处理未压缩的文件夹,而不是解压缩它们然后运行脚本,所有这些都只需一个命令。
我认为管道是一个很好的解决方案,但我以前没有使用过。我该怎么做?
I have a script that I need to run on a large number of files with the extension **.tar.gz*.
Instead of uncompressing them and then running the script, I want to be able to uncompress them as I run the command and then work on the uncompressed folder, all with a single command.
I think a pipe is a good solution for this but i haven't used it before. How would I do this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
-v
命令tar
在提取每个文件时打印文件名:这样脚本将包含处理单个文件的命令,并作为参数传递(感谢 < code>xargs) 到您的脚本(脚本上下文中的
$1
)。编辑:
-I {} -d\\n
部分将使其适用于文件名中的空格。The
-v
orderstar
to print filenames as it extracts each file:This way the script will contain commands to deal with a single file, passed as a parameter (thanks to
xargs
) to your script ($1
in the script context).Edit: the
-I {} -d\\n
part will make it work with spaces in filenames.以下三行 bash...
...将迭代当前目录中的每个 gzipped tarball,解压缩它,获取解压缩内容的最顶层目录并将它们作为参数传递给
somescript.sh.这可能使用比您预期更多的管道,但似乎满足您的要求。
注意:
tar xf
每次调用只能获取一个文件。The following three lines of bash...
...will iterate over each gzipped tarball in the current directory, decompress it, grab the top-most directories of the decompressed contents and pass those as arguments to
somescript.sh
. This probably uses more pipes than you were expecting but seems to do what you are asking for.N.B:
tar xf
can only take one file per invocation.您可以使用 for 循环:
或扩展:
You can use a for loop:
Or expanded: