Last active 9 months ago

此腳本可自動尋找、卸載並彈出所有外接 USB 裝置,確保安全移除磁碟並避免資料損毀。

eject_usb.sh Raw
1#!/bin/bash
2# Script to unmount and eject all external USB drives
3
4# 找到所有外接裝置並處理
5diskutil 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"
10done
11
12