Created
January 9, 2022 13:02
-
-
Save discordianfish/e9e7e01daf1130a1078925744b34a037 to your computer and use it in GitHub Desktop.
List disks with path and id(s)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
set -euo pipefail | |
declare -A paths | |
declare -A ids | |
for f in /dev/disk/by-path/*; do | |
[[ "$f" == *"-part"* ]] && continue | |
paths[$(readlink -f "$f")]+="$(basename "$f") " | |
done | |
for f in /dev/disk/by-id/*; do | |
[[ "$f" == *"-part"* ]] && continue | |
ids[$(readlink -f "$f")]+="$(basename "$f") " | |
done | |
for dev in "${!paths[@]}"; do | |
printf '%s\t%s\t%s\n' "$dev" "${paths[$dev]}" "${ids[$dev]}" | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Sample output (redacted IDs):
Sorted by path by default. It's tab delimited, so you can use
sort
for other sorting, eg by ID: