Skip to content

Instantly share code, notes, and snippets.

@un33k
Created June 3, 2011 18:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save un33k/1006853 to your computer and use it in GitHub Desktop.
Save un33k/1006853 to your computer and use it in GitHub Desktop.
Directory information cleaned up for dispaly
#!/bin/sh
# github:norm:homedir:bin/df
# -*- Mode: Perl; tab-width: 4; indent-tabs-mode: nil; -*-
#
# Present the output of `df` in a more understandable fashion.
# Save this gist as df and put it on your path
/bin/df -h "$@" 2>/dev/null | perl -e '
$prefix = <>;
$longest_fs = 20;
while ( <> ) {
m{
^
( [\S+\s]+? ) \s+ # Filesystem
(\S+) \s+ # Size
(\S+) \s+ # Used
(\S+) \s+ # Avail
(\S+) \s+ # Capacity (%)
(/.*) # Mounted on
$
}x;
push @fs, [ $6, $2, $3, $4, $5 ];
$longest_fs = length( $6 ) if length $6 > $longest_fs;
}
$tmpl = "%-${longest_fs}s %9s %9s %9s %9s\n";
printf $tmpl, "Mounted on", qw( Size Used Avail Capacity );
foreach my $fs ( @fs ) {
printf $tmpl, @{ $fs };
}
'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment