エンジニアのひよこ_level10

毎日更新してた人。たまに記事書きます。

【Linuxコマンド】lsやdfで、数値の100000を10kと表示させる方法【378日目】

こんなときに使う

シェルで、dfコマンドや ls -lコマンド打つと、数値が大きいときに見づらい。
具体的にはこれ。

willow:~$ df
Filesystem    512-blocks      Used Available Capacity iused               ifree %iused  Mounted on
/dev/disk1s1   976695384 369869584 599130216    39% 2137876 9223372036852637931    0%   /

おまけに容量が512バイト単位で数えられる・・・もう一個桁上げてほしい。

これをなんとかしたい。

オプションをつける

オプションをつけると見やすくなる。

-kにすると、1キロバイト単位になる

Filesystem    1024-blocks      Used Available Capacity iused               ifree %iused  Mounted on
/dev/disk1s1    488347692 184936208 299563692    39% 2137901 9223372036852637906    0%   /

-gにすると、1ギガバイト単位になる

willow:~$ df -g
Filesystem    1G-blocks Used Available Capacity iused               ifree %iused  Mounted on
/dev/disk1s1        465  176       285    39% 2137914 9223372036852637893    0%   /

-hは、人間が読める単位にする。

willow:~$ df -h
Filesystem      Size   Used  Avail Capacity iused               ifree %iused  Mounted on
/dev/disk1s1   466Gi  176Gi  286Gi    39% 2137874 9223372036852637933    0%   /

基本的に -hだけで良いと思います。

おまけ:-hの名前の由来

man dfコマンドを読んで見る

     -H      "Human-readable" output.  Use unit suffixes: Byte, Kilobyte, Megabyte, Gigabyte, Terabyte and Petabyte in order to reduce the num-
             ber of digits to three or less using base 10 for sizes.
     -h      "Human-readable" output.  Use unit suffixes: Byte, Kilobyte, Megabyte, Gigabyte, Terabyte and Petabyte in order to reduce the num-
             ber of digits to three or less using base 2 for sizes.

"Human-readable" output.

人間が読めるようにってことですね。