df -h统计的信息与du -sh不一致的原因(转)

df 和 du两者区别 可以快速获取 磁盘 被占用了多少空间,目前还剩下多少空间等信息。显示磁盘空间的使用情况,统计 目录(或文件)所占磁盘空间的大小。是不是感觉字面看起来没啥区别,实际有很多不同哦df 和 du 的不同点:(1)统计的范围不同df 是从总体上统计系统各磁盘的占用情况,不能统计具体的文件夹或文件的大小。du既可以从总体上统计,又可以统计具体的某个文件夹或文件的大小。(2)计算方式不同,计算速度不同df 通过文件系统来快速获取空间大小的信息,速度快,效率高。 阅读详情

有时候会遇到这样的问题:
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级别的目录和文件,并降序排序]

Vue3项目实战:CKEditor5富文本编辑器从安装到隐藏不需要的功能 本文详细介绍了在Vue3项目中集成并深度定制CKEditor5富文本编辑器的完整流程。通过分析其模块化架构,指导开发者从标准构建出发,移除图片、表格等冗余插件,创建专属轻量构建,从而显著减小打包体积并提升用户体验。文章结合实战代码,涵盖了环境搭建、自定义构建配置、高级优化技巧等关键步骤。 阅读详情

相关推荐

RV1126 ISP开发实战:从Tuner调试到IQ文件解析

本文详细介绍了RV1126 ISP开发的完整流程,从Tuner调试到IQ文件解析,涵盖了环境搭建、工具使用、参数配置及性能优化等关键环节。通过实战案例和避坑指南,帮助开发者快速掌握Rockchip芯片的ISP开发技巧,提升图像处理质量。

weixin_29195615的博客 574

df -Th与du -sh空间大小不一致

在日常运维中,经常遇到磁盘空间满,发现占用磁盘空间大的文件已经被删除了,但df -Th查看磁盘空间还是满,没有释放出来但du -sh 查看时发现空间已经腾出来了。

几十年资深高级架构师,技术专家的技术笔记。专注C、Java、Python、微服务、云原生、AI工程化及高并发系统分布式架构实战,分享源码剖析、性能调优与架构治理经验。 1609

Halcon实战:基于图像清晰度自动筛选最佳对焦图片

本文详细介绍了如何使用Halcon实现基于图像清晰度的自动筛选最佳对焦图片技术。通过分析灰度值统计和标准差等核心指标,结合实战代码示例,帮助开发者高效处理工业检测中的对焦问题,提升自动化检测的准确性和效率。

weixin_27015733的博客 444

df -Th与du -sh数据显示不一致,df -Th显示异常

磁盘问题

qq_40584358的博客 3227

用SPSS做信效度分析

对问卷进行Cronbach’s Alpha信度检验。如果此值高于0.8,则说明信度高;如果此值介于0.7-0.8之间,则说明信度较好;如果此值介于0.6~0.7,则说明信度可接受;如果此值小于0.6,说明信度不佳。下面利用SPSS进行分析,点击分析–标度–可靠性分析选项,选中所要分析的问卷数据或题目。得到结果,我们要看这个有用的结果,当克隆巴赫Alpha系数(也可以看标准化后的)大于0.8时候,说明问卷信度较高。

小高~的博客 1万+

Nuvoton OpenTitan开源安全芯片技术解析与应用

硬件安全模块(HSM)作为可信计算基的核心组件,其设计透明度和可验证性正成为行业焦点。RISC-V架构凭借开源特性,为构建可审计的安全芯片提供了新范式。OpenTitan项目通过开放Verilog源码和形式化证明,实现了从物理不可克隆函数(PUF)到分层安全启动的全栈透明。该方案在lowRISC Voyager开发板上实测显示,安全启动时间小于200ms,性能损耗仅7%,显著优于传统黑盒方案。目前该技术已应用于Chromebook和数据中心,其40nm工艺版本更将功耗降至5μA待机水平,为物联网和边缘计算提

weixin_36303807的博客 406

linux查看文件大小信息,df -h和du -sh查询命令查询结果不一样

linux查看文件大小信息,df -h和du -sh查询命令查询结果不一样

99@小程 8万+

ICCV 2025 | 哈工大、清华等提出首个双曲学习框架:HLFormer,革新局部相关视频检索

离原点越远,代表的语义越具体(部分)。现有方法大多在传统的欧几里得空间中对视频和文本进行建模,但这往往会导致对视频内在层次结构的错误表示,从而影响检索的准确性。通过UMAP对学习到的帧嵌入进行可视化(如下图),可以观察到,来自同一时刻的视频帧在嵌入空间中聚集在一起,清晰地展示了模型对时序关系的捕捉能力。下图的双曲空间可视化进一步证实了模型的层次建模能力:离原点越近的点,代表的语义层级越高、粒度越粗糙,反之亦然。:既然文本查询描述的是视频的一部分,那么在几何表示上,文本的嵌入向量应该从属于视频的嵌入向量。

我爱计算机视觉 1088

mysql df -h_df -h和du -sh显示结果不一样的原因及解决

一、背景:一台2T硬盘的mysql服务器,保存电话的CDR信息。按照历史数据的水平,一个月能生成20+GB的文件。然而短短的半年时间,满了?!登录服务器看谁占了这么大的空间?好吧,slow-query.log华丽丽的占用了1.2T!(运维经验严重不足,线上的一定要关闭这个日志,可以执行命令set global slow_query_log=0;)二、BUG出现?1. 很自然的手动删除这个log文件...

weixin_35926485的博客 622

NXP(恩智浦)—TJA1043TK CAN收发器芯片详解

本文章主要讲解NXP(恩智浦)—TJA1043TK CAN收发器的相关知识。

零零刷的博客 2208

用playwright封装一个处理web网页的爬虫,并隐藏自动化特征,自动处理反爬

本文介绍了一个使用Playwright封装的Python爬虫函数,具备反爬对抗能力。该脚本通过移除自动化标志、注入真实用户代理、禁用Chrome自动化属性等措施,有效绕过电商、新闻等中等反爬网站的检测。核心功能包括:隐藏navigator.webdriver标志、模拟人类浏览行为、设置合理的设备参数,并支持代理和延迟加载。使用时需注意避免高频访问并定期更新User-Agent。该方案适用于需要JavaScript渲染的动态网页,性能优于非无头模式。

数据知道的博客 3394

磁盘挂载点du -sh与df -h不一致的原因分析总结

本文分析了磁盘空间告警排查中du与df命令结果不一致的三种常见情况及解决方案:1)存在未释放的deleted文件句柄,可通过lsof+L1查找并重启进程或清空文件;2)磁盘掉盘导致数据写入根分区,需检查挂载点状态;3)磁盘重新挂载覆盖原路径导致数据无法统计,可通过创建临时挂载点查找被覆盖数据。文章提供了详细的排查方法和操作指令,特别针对第三种复杂情况给出了特殊处理方案...

分享不一样的技术,与你一起共同成长! 857

SPI协议详解(图文并茂+超详细)

先说串口 因为之前写过一篇UART,通用串行异步通讯协议,UART的相关资料 因为UART没有时钟信号,无法控制何时发送数据,也无法保证双发按照完全相同的速度接收数据。因此,双方以不同的速度进行数据接收和发送,就会出现问题。 如果要解决这个问题,UART为每个字节添加额外的起始位和停止位,以帮助接收器在数据到达时进行同步; 双方还必须事先就传输速度达成共识(设置相同的波特率,例如每秒9600位)。 传输速率如果有微小差异不是问题,因为接收器会在每个字节的开头重新同步。相应的协议如下图所示; 如果您注意到

一名热爱技术的工程师的博客。分享技术干货,记录美好生活。永远相信美好的事情即将发生。 33万+

df 和 du 两者区别

df 和 du 两者区别 1、 df—disk free 可以快速获取 磁盘 被占用了多少空间,目前还剩下多少空间等信息。 2、du—disk usage 显示磁盘空间的使用情况,统计 目录(或文件)所占磁盘空间的大小。 是不是感觉字面看起来没啥区别,实际有很多不同哦 df 和 du 的不同点: (1)统计的范围不同 df 是从总体上统计系统各磁盘的占用情况,不能统计具体的文件夹或文件的...

Rio520的博客 1万+

汉书HE8,好用的汇编代码编写工具

汉书HE8,好用的汇编代码编写工具早期编写汇编代码所用功能强大

深度学习工具包 DeepLearningToolbox

深度学习工具包Deprecation notice.-----This toolbox is outdated and no longer maintained.There are much better tools available for deep learning than this toolbox, e.g. [Theano](http://deeplearning.net/software/theano/), [torch](http://torch.ch/) or [tensorflow](http://www.tensorflow.org/)I would suggest you use one of the tools mentioned above rather than use this toolbox.Best, Rasmus.DeepLearnToolbox================A Matlab toolbox for Deep Learning.Deep Learning is a new subfield of machine learning that focuses on learning deep hierarchical models of data.It is inspired by the human brain's apparent deep (layered, hierarchical) architecture.A good overview of the theory of Deep Learning theory is[Learning Deep Architectures for AI](http://www.iro.umontreal.ca/~bengioy/papers/ftml_book.pdf)For a more informal introduction, see the following videos by Geoffrey Hinton and Andrew Ng.* [The Next Generation of Neural Networks](http://www.youtube.com/watch?v=AyzOUbkUf3M) (Hinton, 2007)* [Recent Developments in Deep Learning](http://www.youtube.com/watch?v=VdIURAu1-aU) (Hinton, 2010)* [Unsupervised Feature Learning and Deep Learning](http://www.youtube.com/watch?v=ZmNOAtZIgIk) (Ng, 2011)If you use this toolbox in your research please cite [Prediction as a candidate for learning deep hierarchical models of data](http://www2.imm.dtu.dk/pubdb/views/publication_details.php?id=6284)```@MASTERSTHESIS\{IMM2012-06284, author = "R. B. Palm", title = "Prediction as a candidate for learning deep hierarchical models of data", year = "2012",}```Contact: rasmusbergpalm at gmail dot comDirectories included in the toolbox-----------------------------------`NN/` - A library for Feedforward Backpropagation Neural Networks`CNN/` - A library for Convolutional Neural Networks`DBN/` - A library for Deep Belief Networks`SAE/` - A library for Stacked Auto-Encoders`CAE/` - A library for Convolutional Auto-Encoders`util/` - Utility functions used by the libraries`data/` - Data used by the examples`tests/` - unit tests to verify toolbox is workingFor references on each library check REFS.mdSetup-----1. Download.2. addpath(genpath('DeepLearnToolbox'));Example: Deep Belief Network---------------------```matlabfunction test_example_DBNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit RBM and visualize its weightsrand('state',0)dbn.sizes = [100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);figure; visualize(dbn.rbm{1}.W'); % Visualize the RBM weights%% ex2 train a 100-100 hidden unit DBN and use its weights to initialize a NNrand('state',0)%train dbndbn.sizes = [100 100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);%unfold dbn to nnnn = dbnunfoldtonn(dbn, 10);nn.activation_function = 'sigm';%train nnopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.10, 'Too big error');```Example: Stacked Auto-Encoders---------------------```matlabfunction test_example_SAEload mnist_uint8;train_x = double(train_x)/255;test_x = double(test_x)/255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit SDAE and use it to initialize a FFNN% Setup and train a stacked denoising autoencoder (SDAE)rand('state',0)sae = saesetup([784 100]);sae.ae{1}.activation_function = 'sigm';sae.ae{1}.learningRate = 1;sae.ae{1}.inputZeroMaskedFraction = 0.5;opts.numepochs = 1;opts.batchsize = 100;sae = saetrain(sae, train_x, opts);visualize(sae.ae{1}.W{1}(:,2:end)')% Use the SDAE to initialize a FFNNnn = nnsetup([784 100 10]);nn.activation_function = 'sigm';nn.learningRate = 1;nn.W{1} = sae.ae{1}.W{1};% Train the FFNNopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.16, 'Too big error');```Example: Convolutional Neural Nets---------------------```matlabfunction test_example_CNNload mnist_uint8;train_x = double(reshape(train_x',28,28,60000))/255;test_x = double(reshape(test_x',28,28,10000))/255;train_y = double(train_y');test_y = double(test_y');%% ex1 Train a 6c-2s-12c-2s Convolutional neural network %will run 1 epoch in about 200 second and get around 11% error. %With 100 epochs you'll get around 1.2% errorrand('state',0)cnn.layers = { struct('type', 'i') %input layer struct('type', 'c', 'outputmaps', 6, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %sub sampling layer struct('type', 'c', 'outputmaps', 12, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %subsampling layer};cnn = cnnsetup(cnn, train_x, train_y);opts.alpha = 1;opts.batchsize = 50;opts.numepochs = 1;cnn = cnntrain(cnn, train_x, train_y, opts);[er, bad] = cnntest(cnn, test_x, test_y);%plot mean squared errorfigure; plot(cnn.rL);assert(er<0.12, 'Too big error');```Example: Neural Networks---------------------```matlabfunction test_example_NNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);% normalize[train_x, mu, sigma] = zscore(train_x);test_x = normalize(test_x, mu, sigma);%% ex1 vanilla neural netrand('state',0)nn = nnsetup([784 100 10]);opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samples[nn, L] = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.08, 'Too big error');%% ex2 neural net with L2 weight decayrand('state',0)nn = nnsetup([784 100 10]);nn.weightPenaltyL2 = 1e-4; % L2 weight decayopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex3 neural net with dropoutrand('state',0)nn = nnsetup([784 100 10]);nn.dropoutFraction = 0.5; % Dropout fraction opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex4 neural net with sigmoid activation functionrand('state',0)nn = nnsetup([784 100 10]);nn.activation_function = 'sigm'; % Sigmoid activation functionnn.learningRate = 1; % Sigm require a lower learning rateopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex5 plotting functionalityrand('state',0)nn = nnsetup([784 20 10]);opts.numepochs = 5; % Number of full sweeps through datann.output = 'softmax'; % use softmax outputopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex6 neural net with sigmoid activation and plotting of validation and training error% split training data into training and validation datavx = train_x(1:10000,:);tx = train_x(10001:end,:);vy = train_y(1:10000,:);ty = train_y(10001:end,:);rand('state',0)nn = nnsetup([784 20 10]); nn.output = 'softmax'; % use softmax outputopts.numepochs = 5; % Number of full sweeps through dataopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, tx, ty, opts, vx, vy); % nntrain takes validation set as last two arguments (optionally)[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');```[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/rasmusbergpalm/deeplearntoolbox/trend.png)](https://bitdeli.com/free "Bitdeli Badge")

du与df查看信息不一致

使用du与df命令查看磁盘容量不一致 ​​问题描述 在Linux系统中,执行du与df命令查看磁盘容量,出现不一致的现象。 问题1: 执行df -h查看文件系统的使用率,可以看到 /dev/xvdb1磁盘占用了约27G,挂载目录为 /opt ​​​​进入到/opt目录执行du -sh,显示空间总占用量约2.4G, 即df与du命令查看到的结果不一致。 问题2: 通过df -h命令查看磁盘使用情况显...

qq_42937150的博客 1246

数学建模模型总结

这是本人在两年内准备参加数学建模竞赛搜集到的模型资料,已经经过了本人的筛选和整理,希望能够对准备参加数学建模竞赛的学弟学妹们提供一些帮助!

Linux 使用 df 和 du 查询磁盘使用情况 结果不一致

但是当一个文件被删除时,如果还有进程在引用这个文件,根据前文的分析,bmap中不会将这个文件的data block标记为未使用,也就不会将数据块的使用情况更新到superblock中。如果在/mnt目录下有3G的文件,然后在/mnt上挂载了其他文件系统,/mnt下原本那3G的文件就被隐藏起来无法访问,du当然无法统计这部分数据大小(但du会统计挂载在/mnt上的文件),但df会统计这部分信息。它的数据是基于文件获取的,所以有很大的灵活性,不一定非要针对一个分区,可以跨越多个分区操作。

Ruishine的博客 1939

LinePhone3.2.7(android端最新版本) sip客户端

SIP客户端For android:LinePhone3.2.7(最新版本),官网地址:http://www.linphone.org/

linux df/du 结果不一致问题分析

df/du 不一致

岳来的博客 1331

揭秘Linux存储迷局:为何 du -sh 与 df -h 结果大相径庭?

du -sh 与 df -h 的差异并非Bug,而是源于它们设计目的的不同。作为系统管理员,理解这种差异背后的机制,不仅能避免误判磁盘空间不足,更能快速定位隐藏的资源泄漏问题。

这里是技术探索者的前沿阵地。我们聚焦开源技术与IT运维实践,分享深度解析、前沿趋势与实战经验。从代码到云原生,从自动化到智能化运维,共同见证并参与塑造技术的未来。关注我们,一起用开源,定义未来。 897

df和du显示的磁盘空间使用情况不一致的原因及处理

df和du 不一致 磁盘空间 Disk Usage Disk Free lsof

Receptive2WE的博客 1891

Linux使用du和df命令结果不一致

Linux下面通常用du和df命令看磁盘空间的使用情况,基本语法如下: df - report file system disk space usage df [OPTION]... [FILE]... -h, --human-readable print sizes in human readable format (e.g., 1K 234M 2G) du -

博观约取 4726
上一篇: base64 相关知识,不知运用在图片,比如之前的生成excel文件href属性
下一篇: angular2 form reset
蚁族的奋斗1
博客等级 码龄9年 37粉丝 254原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值