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: This script might have to be run under sudo
ONCE because of blkid
. At least on my distro, blkid -o export
will output nil when run as regular user after bootup. This is because in the "regular user rendition" of blkid
, data will actually be retrieved from a cache file (normally /run/blkid/blkid.tab
), which is only writable by root
and will thus require one run under sudo
in order to get populated with current data.
#!/bin/bash
# LICENSE: GPL
if [[ $(id -u) -ne 0 ]]; then
if [[ ! -s /run/blkid/blkid.tab ]]; then
# no cache file found when run as regular user
# this will require one run under sudo to populate cache file
echo -e "Cache file does not exist or is empty.\nPlease give your root password to continue:\n\n"
sudo blkid >/dev/null
fi
fi
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
}'
blkid
tool can tell you label of a known partition. But to find the partition you would have to loop over the output of fdisk.