This is a nifty small feature . Tools like ps,df,du, ls,ps,size,prstat and swap have now the option --scale. This makes the output of those tools much more readable.

Let’s assume we have a directory with three files of varying size:

root@solaris:~# ls -l
total 1991695
-rw-------   1 root     root     536440912 März  1 19:26 narf
-rw-------   1 root     root     1048576 März  1 19:10 testfile
-rw-------   1 root     root     536870912 März  1 19:14 testfile2

This is a little cumbersome to read despite the experienced admin will recognize at least two numbers. The --scale command allows me to control how the output is scaled in a more human readable format.

Let’s at first use a scaling factor of 1024. Values are scaled by dividing by 1024. how often is controlled by the min i have put in front of the 1024. I will later explain the impact off this value.

root@solaris:~# ls -l --scale=min,1024
total 2215977
-rw-------   1 root     root        569M März  1 19:31 narf
-rw-------   1 root     root       1024K März  1 19:10 testfile
-rw-------   1 root     root        512M März  1 19:14 testfile2

Of course you could scale with a factor of 1000 as well.

root@solaris:~# ls -l --scale=min,1000
total 2215977
-rw-------   1 root     root        596M März  1 19:31 narf
-rw-------   1 root     root       1048K März  1 19:10 testfile
-rw-------   1 root     root        537M März  1 19:14 testfile2

If you chose binary scaling, the Unit will be appended with an “i” to make clear that we are talking about Mebibyte oder Kibibyte.

root@solaris:~# ls -l --scale=min,binary
total 2215977
-rw-------   1 root     root       569Mi März  1 19:31 narf
-rw-------   1 root     root      1024Ki März  1 19:10 testfile
-rw-------   1 root     root       512Mi März  1 19:14 testfile2

The unit to which the the numbers are scaled by dividing with the scale factor is set with min, max or minwide.

Min will scale each value to the minimal unit that allows the system to display a value in 5 digits.

root@solaris:~# ls -l --scale=min
total 2215977
-rw-------   1 root     root        569M März  1 19:31 narf
-rw-------   1 root     root       1024K März  1 19:10 testfile
-rw-------   1 root     root        512M März  1 19:14 testfile2

max uses the highest unit that allows the to have a nonzero value in front of a possible decimal. It tries to make the number in front of the unit as low as possible and tries to fit in 5 digits.

root@solaris:~# ls -l --scale=max
total 2215977
-rw-------   1 root     root        569M März  1 19:31 narf
-rw-------   1 root     root          1M März  1 19:10 testfile
-rw-------   1 root     root        512M März  1 19:14 testfile2

minwide is similar to min,except that it tries to fit the the size output in eight instead of five columns

root@solaris:~# ls -l --scale=minwide
total 2215977
-rw-------   1 root     root      582461K März  1 19:31 narf
-rw-------   1 root     root      1048576 März  1 19:10 testfile
-rw-------   1 root     root      524288K März  1 19:14 testfile2

This is a nice demonstration of minimal scaling, as the size of testfile fits in eight columns without scaling the value isn’t scaled at all.

You can use --scale as well with prstat

root@solaris:~# prstat --scale=max,binary
   PID USERNAME   SIZE    RSS STATE   PRI NICE      TIME    CPU PROCESS/NLWP
   963 root      181Mi  160Mi sleep    59    0   0:00:30 0,241% sstored/25
     6 root        0Ki    0Ki sleep    99  -20   0:00:06 0,122% zpool-rpool/166
  1480 root       13Mi    6Mi cpu0     59    0   0:00:00 0,024% prstat/1

du is one additional tool that supports this option:

root@solaris:~# du --scale=max
   3G	.
root@solaris:~# du --scale=min
2782M	.
root@solaris:~# du --scale=minwide
2849154K	.
root@solaris:~# du --scale=min,1024
2782M	.
root@solaris:~# du --scale=min,1000
2917M	.
Written by

Joerg Moellenkamp

Grey-haired, sometimes grey-bearded Windows dismissing Unix guy.