Pull hard disks from /proc/partitions using awk one-liner?

I’m trying to extract the name of the hard disks with an awk one-liner (for the sake of monitoring / alarming) and am having some trouble getting it to do exactly what I want. I thought maybe one of you might be an awk guru and could help me out.

So what I’m trying to do is take /proc/partitions as input and pull unique hard disk devices from it.



major minor  #blocks  name

   8        0  244198584 sda
   8        1      40131 sda1
   8        2  131516416 sda2
   8        3  104862720 sda3
   8        4          1 sda4
   8        5    7767040 sda5
  11        0    1048575 sr0
   8       16 2930266584 sdb

I want something like this returned:


The current awk line I have is as follows:

awk '{ sub(/[0-9]/,"",$NF); }; { print $NF }' /proc/partitions

It doesn’t take into account the first two lines are content I don’t even want to process, nor does it exclude duplicate values (i.e. sda and sda)

I’m not stuck on awk, but it seems like the most elegant (and shortest command) that will get me the results I’m looking for.

If you are wondering why I’m targeting /proc/partitions, it is because I’m trying to make this as distro-agnostic and age independent as possible.

Help, thoughts or ideas are all welcome and appreciated.

What about lsblk?

/usr/bin/lsblk --output NAME,TYPE|/usr/bin/awk '/disk|rom/'

This will only show devices…

lsblk --output NAME,TYPE|awk '/disk|rom/ {print substr ($ 3)}'