du df 区别

虽然知道这两个命令,平时也一直在用,但细想,也就会用,而且时简单用,
常用df查询当前挂载磁盘的使用情况,用du查看当前目录哪个文件占用较多;
df -h
du -ah -d 1
这里小结下:
问题:
1. du df 区别
2. du df 查看的空间为什么不一致

概念:
du estimates and displays the disk space used by files.
可知du基于文件计算和显示磁盘占用情况,
常用命令:

MacBook-air:/ root# du -csh    //统计当前目录占用
 82G    .
 82G    total
MacBook-Air:/ root# du -h -d 1 //统计depth为1所有文件目录占用
 56M    ./.DocumentRevisions-V100
 33M    ./.fseventsd
684M    ./.Spotlight-V100
  0B    ./.Trashes
  0B    ./.vol
 13G    ./Applications
2.5M    ./bin
  0B    ./cores
160M    ./data
4.5K    ./dev
1.0K    ./home
6.3G    ./Library
1.0K    ./net
  0B    ./Network
157M    ./opt
6.2G    ./private
1.0M    ./sbin
5.8G    ./System
 49G    ./Users
540M    ./usr
4.0K    ./Volumes
 82G    .

The df command reports the amount of available disk space being used by file systems.
基于文件系统,意味着不会根据文件是否存在判断当前目录的磁盘占用

yuciermatoMacBook-Air:/ root# df -h  //查看根目录磁盘使用情况
Filesystem      Size   Used  Avail Capacity  iused   ifree %iused  Mounted on
/dev/disk1     112Gi   83Gi   29Gi    75% 21837449 7484277   74%   /
devfs          179Ki  179Ki    0Bi   100%      620       0  100%   /dev
map -hosts       0Bi    0Bi    0Bi   100%        0       0  100%   /net
map auto_home    0Bi    0Bi    0Bi   100%        0       0  100%   /home

回到之前的问题,du和df查看的目录大小不一致,du只会根据目录存在的文件进行统计,如果某个正在运行的进程进行io的文件被删除,du不会统计,但因为对应的句柄未释放,文件系统中仍有此句柄,df仍会有对应的统计;

引用:
[1] https://www.computerhope.com/unix/udu.htm
[2] https://www.computerhope.com/unix/udf.htm

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值