Last active
September 11, 2016 06:37
-
-
Save norm/c6707fdd0a990abbb39c3050fc3430dd to your computer and use it in GitHub Desktop.
A more concise `df` command
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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