用 hdiutil attach 挂载 DMG 或 ISO 镜像
在终端里直接挂载磁盘镜像,并显示挂载路径,方便脚本使用。
运行 hdiutil attach 加镜像路径,镜像就会出现在 Finder 的 /Volumes 下。
01命令
命令
$ hdiutil attach ~/Downloads/AppInstaller.dmg02作用说明
输出最后一行会显示实际挂载位置,脚本中可以用 hdiutil attach image.dmg | tail -1 | cut -f3 提取路径。加 -nobrowse 参数可以让镜像不出现在 Finder 侧栏。卸载时使用 hdiutil detach 加挂载路径,等同于把卷拖到废纸篓。
03风险
!注意: 如果镜像里是安装器,需先把 .app 拷到「应用程序」文件夹再推出镜像才算真正安装。
04撤销
撤销
$ hdiutil detach "/Volumes/AppInstaller"05来源
- Create and work with disk images on Mac依据: Apple documents double-clicking a disk image to mount it, which is what hdiutil does from the command line.
- hdiutil – Create and manipulate disk images依据: hdiutil attach mounts a disk image at /Volumes and prints the mount point; detach unmounts it.
最后验证: 2026-09-18 · 分类: 文件与文件夹