Skip to main content
4 of 10
major improvements
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.)

#!/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= | head -1") | getline lab
              ("blkid -o export "$1" | grep TYPE | cut -f2 -d= | tail -1") | 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