用 hdiutil attach 挂载 DMG 或 ISO 镜像

在终端里直接挂载磁盘镜像,并显示挂载路径,方便脚本使用。

macOS文件hdiutil 磁盘镜像磁盘镜像低风险
运行 hdiutil attach 加镜像路径,镜像就会出现在 Finder 的 /Volumes 下。

01命令

命令
$ hdiutil attach ~/Downloads/AppInstaller.dmg

02作用说明

输出最后一行会显示实际挂载位置,脚本中可以用 hdiutil attach image.dmg | tail -1 | cut -f3 提取路径。加 -nobrowse 参数可以让镜像不出现在 Finder 侧栏。卸载时使用 hdiutil detach 加挂载路径,等同于把卷拖到废纸篓。

03风险

风险低风险
!注意: 如果镜像里是安装器,需先把 .app 拷到「应用程序」文件夹再推出镜像才算真正安装。

04撤销

撤销
$ hdiutil detach "/Volumes/AppInstaller"

05来源

最后验证: 2026-09-18 · 分类: 文件与文件夹

06相关方案