代码之家  ›  专栏  ›  技术社区  ›  dan

有没有办法从命令行中弹出所有外部硬盘?(OS X)

  •  13
  • dan  · 技术社区  · 16 年前

    有没有办法从命令行弹出OS X计算机上安装的所有硬盘驱动器卷?如果我能用shell脚本包装它,那么applescript就可以了。

    5 回复  |  直到 11 年前
        1
  •  10
  •   BastiBen    16 年前

    在终端尝试:

    • umount -a (通过getfsent(3)描述的所有文件系统都已卸载。)
    • umount -A (当前安装的所有文件系统,但根目录未安装的文件系统除外。)

    有关详细信息,请参阅 man umount .

    更新:

    似乎您还可以使用:

    diskutil unmountDisk /dev/disk*
    

    但是没有测试。如果不起作用,请尝试使用“unmount”而不是“unmountdisk”。

    哦,我也发现了 eject 参数(而不是 unmountDisk )这可能也很有趣。

    更新2:

    diskutil eject /dev/* 似乎你在找什么(见评论)。

        2
  •  16
  •   naich    15 年前

    在不知道确切名称的情况下,卸载所有外部硬盘还有另一种优雅的方法:

    osascript -e 'tell application "Finder" to eject (every disk whose ejectable is true)'
    

    要忽略网络安装和光盘,请使用:

    osascript -e 'tell application "Finder" to eject (every disk whose ejectable is true and local volume is true and free space is not equal to 0)'
    
        3
  •  5
  •   Jérôme Verstrynge    15 年前

    我发现这对弹出所有DMG和物理硬盘很有用:

    find /dev -name "disk[1-9]" -exec diskutil eject {} \;
    
        4
  •  0
  •   chopper    12 年前

    您也可以使用 diskutil eject /dev/disk2 或者不管你的设备号是什么,你都想弹出。这对我很有用。

        5
  •  0
  •   dstronczak    11 年前

    我是这样做的:

    df | grep Volumes | awk '{ print $1 }' | while read disk; do diskutil unmount "$disk"; done