azev
V2EX  ›  问与答

du 命令显示 1t 没问题吧?

  •  
  •   azev · Apr 17, 2022 · 1931 views
    This topic created in 1665 days ago, the information mentioned may be changed or developed.
    有个快存满了的 1T 移动硬盘
    du -h 的时候显示 921.2G 可是 du 的时候显示 1931852288
    怎么数也对不上啊?咋回事?
    6 replies  •  2022-04-18 07:11:13 +08:00
    kokutou
    kokutou
    Apr 17, 2022 via Android
    1
    有硬链接?
    alect
    alect
    Apr 17, 2022
    2
    df -h
    azev
    azev
    OP
    Apr 17, 2022
    3
    @alect

    df -h
    /dev/sda1 931.5G 921.3G 10.2G 99% /var/media/onet

    df
    /dev/sda1 976761540 966092840 10668700 99% /var/media/onet
    iBugOne
    iBugOne
    Apr 17, 2022 via Android
    4
    看 man ,du 的默认输出单位是 sector ,也就是 512 字节,1931852288 乘以 512 字节的结果没啥问题
    azev
    azev
    OP
    Apr 17, 2022
    5
    @iBugOne 这个默认貌似是不同发行版不一样? Google 'du 默认输出单位' 不少提及是 kb 为默认单位
    ynyounuo
    ynyounuo
    Apr 18, 2022
    6
    @azev Posix compliant 的单位是 512 bytes ,所以 GNU du 设置了 POSIXLY_CORRECT=1 的话就会用 512 bytes ,BSD du 也一般是 default to 512 bytes

    > The use of 512-byte units is historical practice and maintains compatibility with ls and other
    utilities in this volume of POSIX.1-2017. This does not mandate that the file system itself be
    based on 512-byte blocks.

    https://pubs.opengroup.org/onlinepubs/9699919799/utilities/du.html#RATIONALE
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Privacy   ·   Solana   ·   704 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 30ms · UTC 22:35 · PVG 06:35 · LAX 14:35 · JFK 17:35
    ♥ Do have faith in what you're doing.