我想寫一個shell腳本來卸載/安裝在OS X上的所有外部驅動器命令行卸載操作系統上的所有外部驅動器X
我的磁盤列表如下:
$ diskutil list
/dev/disk0
#: TYPE NAME SIZE IDENTIFIER
0: GUID_partition_scheme *500.3 GB disk0
1: EFI EFI 209.7 MB disk0s1
2: Apple_CoreStorage 499.4 GB disk0s2
3: Apple_Boot Recovery HD 650.0 MB disk0s3
/dev/disk1
#: TYPE NAME SIZE IDENTIFIER
0: Apple_HFS Macintosh HD *496.3 GB disk1
Logical Volume on disk0s2
AE949253-803C-49DC-93EA-7DFC74C2EAA2
Unencrypted
/dev/disk2
#: TYPE NAME SIZE IDENTIFIER
0: GUID_partition_scheme *1.0 TB disk2
1: EFI EFI 209.7 MB disk2s1
2: Apple_HFS Time Machine 999.9 GB disk2s2
/dev/disk3
#: TYPE NAME SIZE IDENTIFIER
0: GUID_partition_scheme *750.2 GB disk3
1: EFI EFI 209.7 MB disk3s1
2: Microsoft Basic Data USB HD 4 749.9 GB disk3s2
/dev/disk4
#: TYPE NAME SIZE IDENTIFIER
0: GUID_partition_scheme *500.1 GB disk4
1: EFI EFI 209.7 MB disk4s1
2: Microsoft Basic Data Backup 499.9 GB disk4s2
/dev/disk5
#: TYPE NAME SIZE IDENTIFIER
0: GUID_partition_scheme *1.0 TB disk5
1: EFI EFI 209.7 MB disk5s1
2: Apple_HFS USB HD 1 999.9 GB disk5s2
/dev/disk6
#: TYPE NAME SIZE IDENTIFIER
0: GUID_partition_scheme *4.0 TB disk6
1: EFI EFI 209.7 MB disk6s1
2: Apple_HFS USB HD 2 4.0 TB disk6s2
/dev/disk8
#: TYPE NAME SIZE IDENTIFIER
0: Apple_partition_scheme *122.9 GB disk8
1: Apple_partition_map 32.3 KB disk8s1
2: Apple_Driver43 28.7 KB disk8s2
3: Apple_Driver43 28.7 KB disk8s3
4: Apple_Driver_ATA 28.7 KB disk8s4
5: Apple_Driver_ATA 28.7 KB disk8s5
6: Apple_FWDriver 262.1 KB disk8s6
7: Apple_Driver_IOKit 262.1 KB disk8s7
8: Apple_Patches 262.1 KB disk8s8
9: Apple_HFS Windows 122.9 GB disk8s9
所以,我寫這樣一個劇本:
#!/bin/sh
diskutil list | grep -oE 'disk[0-9]s2' | while read i
do
Prtl=`diskutil info ${i} | grep Protocol | cut -d ' ' -f 21`
if [ ${Prtl} = USB ]; then
diskutil unmount ${i}
fi
done
我想了解以下內容:
1.Is有一個辦法識別外部驅動器而不使用diskutil信息?原因是diskutil信息啓動睡眠驅動器,我的腳本很慢。
2.有沒有更聰明的方法?我已經谷歌搜索了很多,但我找不到我想要的方式。希望能幫到我...
請教關於http://apple.stackexchange.com – trojanfoe 2014-09-04 18:38:22