ls -6ren">
gpt4 book ai didi

shell - 在字节数和 "human-readable"字符串之间转换

转载 作者:行者123 更新时间:2023-12-04 05:17:08 24 4
gpt4 key购买 nike

是否有一个 shell 命令可以简单地在以字节为单位的数字字符串和某些命令通过 -h 提供的“人类可读”的数字字符串之间来回转换选项?

澄清问题:ls -l没有 -h选项(某些输出被抑制)

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

以字节为单位给出大小,而 -h选项(某些输出被抑制)
> ls -lh 
156M file1.bin
13K file2.bin

大小以千字节和兆字节为单位是人类可读的。

是否有一个 shell 命令可以简单地打开 163564736进入 156M13209进入 13K也可以反过来吗?

最佳答案

numfmt

到:

echo "163564736" | numfmt --to=iec

从:
echo "156M" | numfmt --from=iec

关于shell - 在字节数和 "human-readable"字符串之间转换,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37015073/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com