我意識到這是很老,但它是在谷歌的第一個命中的時候我一直在尋找一個解決類似的東西之一,所以我會後我做了什麼在這裏。我的情況是,我基本上只是想充分爆炸罐,以包含的所有罐子一起略有不同,所以我寫了下面的bash功能:
function explode {
local target="$1"
echo "Exploding $target."
if [ -f "$target" ] ; then
explodeFile "$target"
elif [ -d "$target" ] ; then
while [ "$(find "$target" -type f -regextype posix-egrep -iregex ".*\.(zip|jar|ear|war|sar)")" != "" ] ; do
find "$target" -type f -regextype posix-egrep -iregex ".*\.(zip|jar|ear|war|sar)" -exec bash -c 'source "<file-where-this-function-is-stored>" ; explode "{}"' \;
done
else
echo "Could not find $target."
fi
}
function explodeFile {
local target="$1"
echo "Exploding file $target."
mv "$target" "$target.tmp"
unzip -q "$target.tmp" -d "$target"
rm "$target.tmp"
}
注意,如果你存儲所需要的<file-where-this-function-is-stored>
這在一個文件中,我沒有爲非交互式shell讀取,就像我碰巧那樣。如果你存儲在裝載於在非交互shell文件的功能(例如,.bashrc
我相信)你可以將整個source
聲明。希望這會幫助某人。
一個小警告 - explodeFile
也刪除ziped文件,你當然可以改變的,通過註釋掉的最後一行。
如何處理長文件路徑...超過260個字符...:https://superuser.com/a/1263234/439537 – Andrew 2017-10-28 06:13:49