I would like to get a list of all my hard disks including the following information. Serial Number, UUID, Size and the names and sizes of all of the partitions on each disk. I found this which gets me half way there
for file in $(find /sys/block/[sh][dr]*/device/ /sys/block/[sh][dr]*/ -maxdepth 1 2>/dev/null|egrep '(vendor|model|/size|/sys/block/[sh][dr]./$)'|sort); do [ -d $file ] && echo -e "\n -- DEVICE $(basename $file) --" && continue; grep -H . $file|sed -e 's|^/sys/block/||;s|/d*e*v*i*c*e*/*\(.*\):| \1 |'|awk '{if($2 == "size") {printf "%-3s %-6s: %d MB\n", $1,$2,(($3 * 512)/1048576)} else {printf "%-3s %-6s: ", $1,$2;for(i=3;i<NF;++i) printf "%s ",$i;print $(NF) };}';done
My preference is for it to go to a text file. I assume I can do that just by adding "> ~/disks.txt" to the end of the line
Would really appreciate it if someone could help me figure out how to modify the command so it adds partition names and sizes.
0 Answers