linux - 批量解压到文件夹路径
问题描述
我有带有域的基于 Linux 的服务器:
domain1.com
public_html
archive1.zip
domain2.com
public_html
archive2.zip
domain3.com
public_html
archive3.zip
我正在尝试通过以下方式运行解压缩:
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
PS:我打算用来移动到目录,但@Mihir在他们的评论中pushd
提供了更简单的解决方案。-d
PPS:您不需要脚本来运行它 - 只需在 bash 提示符下逐字输入,包括换行符。或者你可以把它折叠成一个衬里:
for archive in */public_html/*.zip; do unzip "$archive" -d "$( dirname "$archive" )"; done
要么,bash
命令历史记录将让您返回到您键入和修改的内容和/或根据需要重新运行它。
推荐阅读
- firebase - 只有用户可以修改在 Firebase 中有自己的数据
- android - 在活动中的片段中按下后退按钮后出现空白屏幕
- image-masking - 重叠发生而不是在掩码上上传图像
- c++ - 为什么调用复制构造函数
- r - 如何在R中创建坐标系并定位点?
- python - Matplotlib(pyplot) 'str' 对象在尝试更改 y-label 时不可调用
- c# - 无法检索使用应用程序权限与用户共享的 OneDrive 文件
- shell - 仅允许指定字符,否则 null 应在 unix 中传输
- mysql - 使用 Laravel Forge 和 Digital Ocean 拒绝 Mysql 访问
- c# - 项目设置中的条件自定义操作