希望能就这一问题提供投入。我有来自macOS (High;FileSystem :APFS)命令- diskutil apfs list的输出。样本输出如下:
+-- Container disk5 1B5FE22B-6F4F-4EB9-8AA3-D326E4E940DF
| ====================================================
| APFS Container Reference: disk5
| Size (Capacity Ceiling): 250140434432 B (250.1 GB)
| Minimum Size: 192333017088 B (192.3 GB)
| Capacity In Use By Volumes: 186220453888 B (186.2 GB) (74.4% used)
| Capacity Not Allocated: 63919980544 B (63.9 GB) (25.6% free)
| |
| +-< Physical Store disk4s2 E6FF882B-995C-4C60-B164-76923667F8A1
| | -----------------------------------------------------------
| | APFS Physical Store Disk: disk4s2
| | Size: 250140434432 B (250.1 GB)
| |
| +-> Volume disk5s1 7BB363F8-A658-4B6C-A4B4-778AC782785E
| | ---------------------------------------------------
| | APFS Volume Disk (Role): disk5s1 (No specific role)
| | Name: Macintosh HD (Case-insensitive)
| | Mount Point: Not Mounted
| | Capacity Consumed: 181760897024 B (181.8 GB)
| | FileVault: Yes (Locked)
| |
| +-> Volume disk5s2 48A79DA5-1228-4F5A-8851-5178B91D2310
| | ---------------------------------------------------
| | APFS Volume Disk (Role): disk5s2 (Preboot)
| | Name: Preboot (Case-insensitive)
| | Mount Point: Not Mounted
| | Capacity Consumed: 66613248 B (66.6 MB)
| | FileVault: No
| |
| +-> Volume disk5s3 D46C3FA0-5B9D-4E13-9327-EEFB483F692E
| | ---------------------------------------------------
| | APFS Volume Disk (Role): disk5s3 (Recovery)
| | Name: Recovery (Case-insensitive)
| | Mount Point: Not Mounted
| | Capacity Consumed: 1033371648 B (1.0 GB)
| | FileVault: No
| |
| +-> Volume disk5s4 3E852266-E0C3-48AB-ACAD-D73CEE0134F1
| ---------------------------------------------------
| APFS Volume Disk (Role): disk5s4 (VM)
| Name: VM (Case-insensitive)
| Mount Point: Not Mounted
| Capacity Consumed: 3221250048 B (3.2 GB)
| FileVault: No我的目标是:
我想出了以下几点:
diskutil apfs list|awk '/[A-Z0-9]{8}-([A-Z0-9]{4}-){3}[A-Z0-9]{12}$|.l/{print}'输出:
+-- Container disk5 1B5FE22B-6F4F-4EB9-8AA3-D326E4E940DF
| Size (Capacity Ceiling): 250140434432 B (250.1 GB)
| Capacity In Use By Volumes: 186220453888 B (186.2 GB) (74.4% used)
| Capacity Not Allocated: 63919980544 B (63.9 GB) (25.6% free)
| +-< Physical Store disk4s2 E6FF882B-995C-4C60-B164-76923667F8A1
| | APFS Physical Store Disk: disk4s2
| +-> Volume disk5s1 7BB363F8-A658-4B6C-A4B4-778AC782785E
| | APFS Volume Disk (Role): disk5s1 (No specific role)
| | FileVault: Yes (Locked)
| +-> Volume disk5s2 48A79DA5-1228-4F5A-8851-5178B91D2310
| | APFS Volume Disk (Role): disk5s2 (Preboot)
| | FileVault: No
| +-> Volume disk5s3 D46C3FA0-5B9D-4E13-9327-EEFB483F692E
| | APFS Volume Disk (Role): disk5s3 (Recovery)
| | FileVault: No
| +-> Volume disk5s4 3E852266-E0C3-48AB-ACAD-D73CEE0134F1
| APFS Volume Disk (Role): disk5s4 (VM)
| FileVault: No欢迎用于更正/修改代码的任何输入:)。提前感谢
发布于 2019-03-19 17:37:02
转换结构化XML输出的马克·普罗尼克的建议。
diskutil apfs list -plist转换为JSON并使用jq解析它。jq实用程序可以从macOS上的Homebrew中获得。
这必须分两个步骤完成,因为plutil需要读取一个常规文件:
diskutil apfs list -plist >list.xml
plutil -convert json -o list.json list.xml从生成的JSON文件中,我们可以提取已启用FileVault并已锁定的所有卷的APFS卷UUID,使用
jq -r '.Containers[].Volumes[] | select(.FileVault == true and .Locked == true) | .APFSVolumeUUID' list.json在一个“单一”命令中,将其赋值给一个变量:
locked_uuids=$(
diskutil apfs list -plist >list.xml
plutil -convert json -o list.json list.xml
jq -r '.Containers[].Volumes[] | select(.FileVault == true and .Locked == true) | .APFSVolumeUUID' list.json
rm -f list.xml list.json
)请注意,上面的命令覆盖和删除当前目录中的两个文件list.xml和list.json。您可能希望使用mktemp创建临时文件:
locked_uuids=$(
tmpxml=$(mktemp)
tmpjson=$(mktemp)
diskutil apfs list -plist >"$tmpxml"
plutil -convert json -o "$tmpjson" "$tmpxml"
jq -r '.Containers[].Volumes[] | select(.FileVault == true and .Locked == true) | .APFSVolumeUUID' "$tmpjson"
rm -f "$tmpxml" "$tmpjson"
)为了方便起见,您可能希望将这些命令放入一个shell函数中,然后调用它(在这里使用bash ):
list_locked_vaults () {
local tmpxml=$(mktemp)
local tmpjson=$(mktemp)
diskutil apfs list -plist >"$tmpxml"
plutil -convert json -o "$tmpjson" "$tmpxml"
jq -r '.Containers[].Volumes[] | select(.FileVault == true and .Locked == true) | .APFSVolumeUUID' "$tmpjson"
rm -f "$tmpxml" "$tmpjson"
}
locked_uuids=$( list_locked_vaults )https://unix.stackexchange.com/questions/507217
复制相似问题