Created
January 9, 2022 13:02
List disks with path and id(s)
This file contains hidden or 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: