#!/bin/bash
arguments=()
sortargs=()
for arg ; do
    case "$arg" in
    --sort?volume)      sortargs=(   ) ;;
    --sort?size)        sortargs=(+1n) ;;
    --sort?used)        sortargs=(+2n) ;;
    --sort?available)   sortargs=(+3n) ;;
    --sort?percent)     sortargs=(+4n) ;;
    --sort?mount-point) sortargs=(+5 ) ;;
    +[0-9]*)            sortargs[${#sortargs}]="$arg"   ;;
    *)                  arguments[${#arguments}]="$arg" ;;
    esac
done

/bin/df ${arguments[@]} \
| awk '
BEGIN{
    num=0;
    maxlength1=20;
}
/^ /{
    if(length(lines[num])>maxlength1){
        maxlength1=length(lines[num]);
    }
    lines[num]=lines[num]" "$0;
    next;
}
{
    num++;
    lines[num]=$0;
    next;
}
END{
    print maxlength1;
    for(i=1;i<=num;i++){
       print lines[i];
    }
}' \
| awk '
BEGIN {
    first=1;
}
{
    if(first!=0){
        maxlength1=$1;
        format=sprintf("%%-%ds %%9s %%9s %%9s %%4s %%s\n",maxlength1);
        first=0;
    }else{
        printf format,$1,$2,$3,$4,$5,$6" "$7" "$8" "$9;
    }
}' \
| ( read line ; echo "$line" ; sort ${sortargs[@]} )
#### df                               -- 2004-01-21 01:30:22 -- pascal   ####
ViewGit