Skip to content

Instantly share code, notes, and snippets.

@norm
Last active September 11, 2016 06:37
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 norm/c6707fdd0a990abbb39c3050fc3430dd to your computer and use it in GitHub Desktop.
Save norm/c6707fdd0a990abbb39c3050fc3430dd to your computer and use it in GitHub Desktop.
A more concise `df` command
#!/bin/sh
/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 (%)
(?:
\S+ \s+ # iused
\S+ \s+ # ifree
\S+ \s+ # %iused
)
(/.*) # 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