On Sun, Nov 07, 2021 at 07:46:37PM -0300, Crystal Kolipe wrote:
> >     df(1) is missing the standard options to display size units in
> >     Megabytes or Gigabytes.
> 
> alias df_m="df | perl -e '<>; print ("Filesystem    1M-blocks       Used   
> Available Capacity  Mounted on\n"); while ($i=<>) { $i =~ /^(.*?) +(\d+) 
> +(\d+) +(\d+)(.*)/; printf ("%s % 13d % 10d % 
> 11d%s\n",$1,int($2/2048),int($3/2048),int($4/2048),$5); }'"

Not saying whether this is a good idea, but perl can do this slightly
more easily, and we can handle the dynamic width of the first column
without adding too many characters, but handling the -i flag (or others)
is left as an exercise for the reader.

$ df | perl -aE 'if ($maxwidth) { $_ /= 2048 for @F[1..3] ; printf 
"%-${maxwidth}s %9.2f %9.2f %9.2f %6s    %s\n", @F } else { s/^(.*?)\K 1K-/ 
1M-/; $maxwidth = length $1; print }'

l8rZ,
-- 
andrew - http://afresh1.com

A printer consists of three main parts:
        the case, the jammed paper tray and the blinking red light.

Reply via email to