Skip to main content
3 of 10
made script POSIX compatible
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 = "%-12s\x27%-17s\x27\t%-10s\t%4s used\n"
              printf fmthdr, " Device ",  "Volume Label", "File System", "Storage usage"
              printf fmthdr, "---------", "------------", "-----------", "-------------"
            } 
            /^\/dev\/[sh]/{ 
              ("blkid -o export "$1" | cut -f2 -d= | head -1") | getline lab 
              ("blkid -o export "$1" | cut -f2 -d= | tail -1") | getline fs
              printf fmtlin, $1, lab, fs, $5 
            }'
syntaxerror
  • 2.4k
  • 2
  • 31
  • 52