Several command line tools use the -h
or --human-readable
option to print file size in a human readable format (i.e., 36G
vs 37550836
).
- Why is this option needed and not the default?
- Aren't these tools mainly for output to humans?
Several command line tools use the -h
or --human-readable
option to print file size in a human readable format (i.e., 36G
vs 37550836
).
ls
, but parsing the output of du
or df
is relatively common. (Mind, for df
, you should use df -P
when parsing.)Note that if you set BLOCKSIZE=human-readable in your environment, this will be the default, at least for the commands from GNU coreutils, i.e. if you're using bash put:
export BLOCKSIZE=human-readable
in your $HOME/.bashrc file.
BLOCK_SIZE=human-readable
. Also didn't know about support for thousands separators until I read that.
– Mikel
Apr 13 '12 at 05:38
Beside what Gilles said:
When these tools where invented hdd was very small, compared with today. You didn't need help to read a number like 400000.
And if you don't like it, use the alias system. In your home directory,
edit ~/.bashrc
and insert, for example:
alias df='df -h'
alias du='du -h'
Note that in contrast to many other languages, you aren't allowed to have a blank before or behind the assignment operator (equal sign).
sort -n
because I'm less interested in quickly seeing the rough size of each directory and more in which subdirectory is taking up disproportionally too much space... – Shadur-don't-feed-the-AI Nov 14 '11 at 08:41-h
too! – quodlibetor Nov 14 '11 at 19:52sort -h
was introduced in GNU coreutils 7.5. Lucid has 7.4, so on Ubuntu you need at least maverick. – Gilles 'SO- stop being evil' Nov 19 '11 at 02:30