zoukankan      html  css  js  c++  java
  • df -h统计的信息与du -sh不一致的原因(转)

    有时候会遇到这样的问题:
    df -h统计一个目录,显示有约100M可用空间,使用了5G;
    而用du -sh统计该目录下的文件大小,却发现总共才占用了1G。
    也就是说,二者统计结果差距巨大。

    例如:

    1、df -h /tmp/

    结果:

    Size Used Avail Use% Mounted on
    3.9G 3.5G 220M 95% /tmp

    2、du -sh /tmp/

    结果:

    132K    /tmp/

    文章来源:http://www.codelast.com/

    结果差异巨大。

    引用网上的一段话,原因是这样的:

    (1)This section gives the technical explanation of why du and df sometimes report different totals of disk space usage.
    When a program that is running in the background writes to a file while the process is running, the file to which this process is writing is deleted. 
    Running df and du shows a discrepancy in the amount of disk space usage. The df command shows a higher value.2)The difference is that whenever an application has an open file, but the file is already deleted, 
    then it is counted in the df output (because the space is certainly not free) 
    but not in du (because it is not being used by a file).

    如何查看是什么进程导致的问题?

    假设你发现是 /tmp/ 目录不对劲,那么就这样就可以查看:

    lsof | grep /tmp/

    输出的结果中,注意某些含有“(deleted)”字样的记录,它们中的一部分就是罪魁祸首,将它们kill掉即可(如果可以重启这些进程所对应的服务的话,也有可能解决问题)。

    http://www.codelast.com/?p=1066


    汇总一些原理分析
    实现原理:
    du -s命令通过将指定文件系统中所有的目录、符号链接和文件使用的块数累加得到该文件系统使用的总块数;
    df命令通过查看文件系统磁盘块分配图得出总块数与剩余块数。
    du是用户级程序,不考虑Meta Data(系统为自身分配的一些磁盘块)

    ps:应用程序打开的文件句柄没有关闭的话,会造成df命令显示的剩余磁盘空间少。而du则不会。


    [root@hadoop01 ~]# du -sh . [对当前目录下所有的目录和文件的大小进行汇总,-s表示汇总,-h表示以KB, MB, GB, TB格式进行人性化显示]
    [root@hadoop01 ~]# du -sh *|grep [MG]|sort -nr  [筛选出大小为MB和GB级别的目录和文件,并降序排序]

  • 相关阅读:
    【POJ 3525】Most Distant Point from the Sea(直线平移、半平面交)
    【HDU 4940】Destroy Transportation system(无源无汇带上下界可行流)
    codevs 5962 [SDOI2017]数字表格
    【NOIP2016】天天爱跑步
    [2011WorldFinal]Chips Challenge[流量平衡]
    [Ahoi2014]支线剧情[无源汇有下界最小费用可行流]
    [NOI2008] 志愿者招募[流量平衡]
    [Wc2007]剪刀石头布[补集转化+拆边]
    poj3281 Dining[最大流]
    1458: 士兵占领[最大流]
  • 原文地址:https://www.cnblogs.com/softidea/p/4237084.html
Copyright © 2011-2022 走看看