# The default unit of `du` command, why is it implicit?



## jronald (May 19, 2013)

```
# du
123456
```
This result should be in byte by default, but it is in kilobyte in fact. This is not complete.
BTW, the document doesn't mention the default unit of the result in this case.


----------



## bkouhi (May 19, 2013)

I guess this is in KB because of this line in your ~/.cshrc


```
setenv  BLOCKSIZE       K
```

Change it to M to get the size in Megabytes or G for Gigabytes.

Please see `man environ | less -p BLOCKSIZE` for more information.


----------



## jronald (May 20, 2013)

bkouhi said:
			
		

> I guess this is in KB because of this line in your ~/.cshrc
> 
> 
> ```
> ...



It is a little complex, if a unit is added in the result, it is completed by itself.


----------



## fluca1978 (May 22, 2013)

jronald said:
			
		

> It is a little complex, if a unit is added in the result, it is completed by itself.



That's why there is a -h option to several commands that use BLOCKSIZE. The idea of having commands outputting numbers is useful when you have to elaborate such results in scripts and do not have to deal with alpha-numerical strings.


----------



## Uniballer (May 22, 2013)

I like it, too.  But wouldn't it be nice if sort had a -h switch to accept that output format for sorting input? E.g. `du -hcs * | sort -h`

I know, if I wasn't being lazy I would just do it myself.


----------



## fluca1978 (May 23, 2013)

Uniballer said:
			
		

> I like it, too.  But wouldn't it be nice if sort had a -h switch to accept that output format for sorting input? E.g. `du -hcs * | sort -h`



I'm not sure that adding extra switches to other commands is the right solution. I mean, the -h flag is used when the next element in the _pipe_ is the human, not another program.
So I see more the usage of a small awk(1) script or the usage of units(1) or stuff like that to solve the problem you mention.


----------



## jronald (May 25, 2013)

fluca1978 said:
			
		

> That's why there is a -h option to several commands that use BLOCKSIZE. The idea of having commands outputting numbers is useful when you have to elaborate such results in scripts and do not have to deal with alpha-numerical strings.



If it is going to support script, additional options could be there.
By default it should be self-explained.


----------

