Convert between byte count and “human-readable” st

2019-04-08 02:41发布

Is there a shell command that simply converts back and forth between a number string in bytes and the "human-readable" number string offered by some commands via the -h option?

To clarify the question: ls -l without the -h option (some output supressed)

> ls -l 
  163564736 file1.bin
      13209 file2.bin

gives the size in bytes, while with the -hoption (some output supressed)

> ls -lh 
  156M file1.bin
   13K file2.bin

the size is human readable in kilobytes and megabytes.

Is there a shell command that simply turns 163564736into 156M and 13209 into 13K and also does the reverse?

标签: shell
2条回答
2楼-- · 2019-04-08 03:09

numfmt

To:

echo "163564736" | numfmt --to=iec

From:

echo "156M" | numfmt --from=iec
查看更多
【Aperson】
3楼-- · 2019-04-08 03:16

There is no standard (cross-platform) tool to do it. But solution using awk is described here

查看更多
登录 后发表回答