timmy / 卸載與彈出外接 USB 裝置腳本
0 likes
0 forks
1 files
Last active 9 months ago
此腳本可自動尋找、卸載並彈出所有外接 USB 裝置,確保安全移除磁碟並避免資料損毀。
| 1 | #!/bin/bash |
| 2 | # Script to unmount and eject all external USB drives |
| 3 | |
| 4 | # 找到所有外接裝置並處理 |
| 5 | diskutil list | grep "external, physical" | awk '{print $1}' | while read -r disk; do |
| 6 | echo "Unmounting all volumes on $disk..." |
| 7 | diskutil unmountDisk "$disk" |
| 8 | echo "Ejecting $disk..." |
| 9 | diskutil eject "$disk" |
| 10 | done |
Newer
Older