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

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/2049758/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-21 06:40:25  来源:igfitidea点击:

is there a way to eject all external hard drives from the command line? (OS X)

macoscommand-lineapplescript

提问by dan

Is there a way to eject all the mounted hard drive volumes on an OS X computer from the command line? Applescript is OK if I can wrap that in a shell script.

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

采纳答案by BastiBen

In Terminal try:

在终端尝试:

  • umount -a(All the filesystems described via getfsent(3) are unmounted.)
  • umount -A(All the currently mounted filesystems except the root unmounted.)
  • umount -a(通过 getfsent(3) 描述的所有文件系统都已卸载。)
  • umount -A(除根目录外,所有当前挂载的文件系统都已卸载。)

Fore more information see man umount.

欲了解更多信息,请参阅man umount

Update:

更新:

Seems like you can also use this:

好像你也可以用这个:

diskutil unmountDisk /dev/disk*

Didn't test it, though. If it doesn't work, try to use "unmount" instead of "unmountDisk".

不过没试过。如果它不起作用,请尝试使用“unmount”而不是“unmountDisk”。

Oh, I also found the ejectargument (instead of unmountDisk). That might also be of interest.

哦,我也找到了eject论点(而不是unmountDisk)。这可能也很有趣。

Update 2:

更新 2:

diskutil eject /dev/*seems what you are looking for (see comments).

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

回答by naich

There is another elegant way to unmount all external hard drives without knowing the exact names:

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

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

To ignore network mounts and optical disks, use:

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

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)'

回答by StumblingMages

I found this to work for ejecting all dmg and physical hard drives:

我发现这适用于弹出所有 dmg 和物理硬盘:

find /dev -name "disk[1-9]" -exec diskutil eject {} \;

回答by Richard Johnson

You can also use diskutil eject /dev/disk2or whatever your device number is you want to eject. That worked for me.

您也可以使用diskutil eject /dev/disk2或任何您想要弹出的设备编号。那对我有用。

回答by dstronczak

I do it like this:

我这样做:

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