To address the listing of the unmounted partitions part, there are several ways - lsblkfdiskpartedblkid.

We can use a little bit of AWK magic to parse the output of lsblk to list all the unmounted partitions :

 
$ lsblk  --noheadings --raw | awk '$1~/s.*[[:digit:]]/ && $7==""'              
sdb1 8:17 0 1.5G 0 part 
sdb3 8:19 0 8.1G 0 part 
sdb4 8:20 0 1K 0 part 
sdb5 8:21 0 68.5G 0 part 
sdb6 8:22 0 5.8G 0 part

Or alternatively:

 
$ lsblk --noheadings --raw -o NAME,MOUNTPOINT | awk '$1~/[[:digit:]]/ && $2 == ""'                                       
sdb1 
sdb2 
sdb3 
sdb4 
sdb5

What exactly is happening here is that we're listing all the lines which have the first column starting with letter s (because that's how drives typically are named) and ending with a number (which represent partitions). 


Was this answer helpful? 0 Users Found This Useful (0 Votes)