Linux: Display Hard Drive Serial Number For Each Device
I needed to physically replace a drive in an array and to do that I needed the serial number of the drive. for i in $(awk '/sd[a-z]+$/ { print $4 }' /proc/partitions | sort); do printf "%-5s%s\n" $i "$(smartctl -i /dev/$i | grep Serial | sed 's/^[^:]\+:[[:space:]]\+\([[:alnum:]\-]\+\)/\1/')"; done sda WD-WXL708065381 sdaa Z1F1HLJN sdb Z1F0YPP2 sdc Z1F136GZ sdd Z1F0X9X7 sde Z1F136DE sdf Z1F1HM91 sdg 9WM66QZP sdh 9WM73LV3 sdi 9WM6JLJT sdj 9WM73600 sdk 9WM6Y6B5 sdl Z1F1HLMY sdm 9XH024P1 sdn 9XH025HS sdo 9XH01Y60 sdp 9XH025PY sdq 9WM6KMP3 sdr 9WM6PESG sds 9WM6QFZP sdt 9WM66ZY9 sdu 9WM6SAL6 sdv Z1F1LVP2 sdw Z1F11NKT sdx Z1F11LB7 sdy Z1F11NVV sdz Z1F11MEF