This question already has answers here:

Unzip All Files In A Directory
(15个答案)
我有一个基于Linux的服务器,其域为:
domain1.com
   public_html
      archive1.zip
domain2.com
   public_html
      archive2.zip
domain3.com
   public_html
      archive3.zip

我试着用以下方式运行unziping:
unzip */public_html/*.zip

它在一个域中工作得很好(除了它在我启动此命令的文件夹中解压)。
批量解压是否有方法获得以下输出:
domain1.com
   public_html
      archive1.zip
      content_of_archive1
domain2.com
   public_html
      archive2.zip
      content_of_archive2
domain3.com
   public_html
      archive3.zip
      content_of_archive3

谢谢你的时间和帮助!

最佳答案

这需要一个for循环:

for archive in */public_html/*.zip; do
   unzip "$archive" -d "$( dirname "$archive" )"
done

注:我本来打算使用pushd移动到目录,但是@mihir在他们的评论中提供了一个更简单的解决方案。
pps:您不需要脚本来运行它-只需在bash提示符下逐字输入,包括换行符。或者你可以把它折成一行:
for archive in */public_html/*.zip; do unzip "$archive" -d "$( dirname "$archive" )"; done

或者,-d命令历史将允许您返回到您键入的内容和修改器,和/或根据需要重新运行它。

关于linux - 批量解压缩到文件夹路径,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/57135753/

10-10 17:38