如何用shell脚本解压缩所有.tar.gz? [英] How to untar all .tar.gz with shell-script?
本文介绍了如何用shell脚本解压缩所有.tar.gz?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我尝试过:
DIR=/path/tar/*.gz
if [ "$(ls -A $DIR 2> /dev/null)" == "" ]; then
echo "not gz"
else
tar -zxvf /path/tar/*.gz -C /path/tar
fi
如果该文件夹包含一个tar,则可以使用.如果文件夹中有很多tar,我会收到错误消息.
If the folder has one tar, it works. If the folder has many tar, I get an error.
我该怎么做?
我有一个想法可以运行循环以解压缩,但是我不知道如何解决这个问题
I have an idea to run a loop to untar, but I don't know how to solve this problem
推荐答案
for f in *.tar.gz
do
tar zxvf "$f" -C /path/tar
done
这篇关于如何用shell脚本解压缩所有.tar.gz?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文