Skip to main content
7 of 10
added 199 characters in body
syntaxerror
  • 2.4k
  • 2
  • 31
  • 52

If you like, you can use my bash script for that purpose. It actually does a little more than you need, i. e. it will also show how much space is used. Hope you like it :) And I also hope that the output will be as neat as on my linux box... (Note: it will only show real hardware like your HDDs and DVD-ROMs, but that's sufficient for my purposes.)

Important note: On Ubuntu and flavors, this script might have to be run under sudo because of blkid. At least on my distro, blkid -o export will output nil when run as regular user. This must have been changed recently, because on Saucy this was still working fine.

#!/bin/bash
# LICENSE: GPL

df -P |
sort  |
awk 'BEGIN {
             fmthdr = "%-12s%-22s%-10s\t%-5s\n"

         # since we want to use single quotes for showing label names, we had better
         # replace the problematic single quote character by its hex representation, "\x27"
             fmtlin_w_qu = "%-12s\x27%-17s\x27\t   %-10s\t%4s used\n"
             fmtlin_wo_qu = "%-12s%-17s\t   %-10s\t%4s used\n"

             printf fmthdr, " Device ",  "Volume Label", "File System", "Storage usage"
             printf fmthdr, "---------", "------------", "-----------", "-------------"
           }    
           /^\/dev\/[sh]/{
              lab = ""      # CLEAR lab w/every run (very important!)
              ("blkid -o export "$1" | grep LABEL | cut -f2 -d=") | getline lab
              ("blkid -o export "$1" | grep TYPE | cut -f2 -d=") | getline fs
              if (lab == "") {
                lab = "<none>"
                fmtlin = fmtlin_wo_qu
              }
              else
                fmtlin = fmtlin_w_qu

              printf fmtlin, $1, lab, fs, $5
           }'
syntaxerror
  • 2.4k
  • 2
  • 31
  • 52