使用 du 差异与 df 的目录大小

使用 du 差异与 df 的目录大小

/var/moodle-docker-deploy我们对位于/var文件系统内的目录大小感兴趣:

root@moodle2prod:/var/moodle-docker-deploy# du -sh .
1,4T    .

使用 df,/var文件系统仅使用 334 GB:

root@moodle2prod:/var/moodle-docker-deploy# df -BG |more
S.ficheros     bloques de 1G Usados Disponibles Uso% Montado en
udev                     32G     0G         32G   0% /dev
tmpfs                     7G     1G          6G  10% /run
/dev/md2                 96G     3G         89G   4% /
tmpfs                    32G     0G         32G   0% /dev/shm
tmpfs                     1G     0G          1G   0% /run/lock
tmpfs                    32G     0G         32G   0% /sys/fs/cgroup
/dev/md4               7191G   334G       6495G   5% /var
overlay                7191G   334G       6495G   5% /var/lib/docker/overlay2/97a287ee173992625df39492d892731346d3c29420091353250e07db05943cd4/merged
shm                       1G     0G          1G   0% /var/lib/docker/containers/fbd8b6353ada35db8b1f3b492ce3170c674bc233a9cf9e6a54f8aefa158c765e/mounts/shm
overlay                7191G   334G       6495G   5% /var/lib/docker/overlay2/ed594aa9d8e387a485e58edffbbb7df561e73d31075770f8ce4408ca78d4718d/merged
shm                       1G     0G          1G   0% /var/lib/docker/containers/e6ffdb11ba1098832745914b8dc5c4976a27c275f121a4006b8d307dca7a4574/mounts/shm
overlay                7191G   334G       6495G   5% /var/lib/docker/overlay2/b773d069d8b9727477508cb6824abc400963bfa8ef7b4b46dcd3834671f70608/merged
shm                       1G     0G          1G   0% /var/lib/docker/containers/deb9f75bc55ea5a3398bd283c7c6fcc7a54e0751c7d92d53b222c43fb5059ff3/mounts/shm
overlay                7191G   334G       6495G   5% /var/lib/docker/overlay2/ea84b0e4cf6975fd73a9353fc890ebc49023f888f84c839dda14708dc159485b/merged
overlay                7191G   334G       6495G   5% /var/lib/docker/overlay2/cbefb54fc600d93de1ec83c347c7e832ed85441cbf85220d8ed5e17cb535cb53/merged
overlay                7191G   334G       6495G   5% /var/lib/docker/overlay2/45dfbde8508ce8beecf608cbc16a54364cb67d34d3cb490315d5f1592e2f2094/merged
overlay                7191G   334G       6495G   5% /var/lib/docker/overlay2/e79309b0ad72ff5382ecb70fff21b8d5c9353b54c78b13c5d2266a3b2b71963a/merged
overlay                7191G   334G       6495G   5% /var/lib/docker/overlay2/29897debfc5c60a58b5e7fd443171d093e90fc0ccbf8268ef40b82a1d10240b5/merged
overlay                7191G   334G       6495G   5% /var/lib/docker/overlay2/f13bf05da7380c4429a1b4c8a6c57b1f8c3eac767e5da01f65fe8ef408d5f183/merged
overlay                7191G   334G       6495G   5% /var/lib/docker/overlay2/5fcb414bc46d1fe18a25304c14dedb542c904d42a45137c5e25ec389558322a3/merged
overlay                7191G   334G       6495G   5% /var/lib/docker/overlay2/b68bc3064dc660f8e44387fab53c37b87fc96176b66e12aec44fa67f14c4c8cf/merged
overlay                7191G   334G       6495G   5% /var/lib/docker/overlay2/5e236f838dbe585a474b64d3d477c4a6ece3ccad6d565e728b636e17967f6a1a/merged
overlay                7191G   334G       6495G   5% /var/lib/docker/overlay2/e3ac5e0f3f8a98d599b47d6219486b9b6a573984803c3e11af2127d273960b3a/merged
overlay                7191G   334G       6495G   5% /var/lib/docker/overlay2/0231fc00f2ea5c6baf60e22cbb42d08bba0d47f4e04fd60789440a6eb6b9dca7/merged
overlay                7191G   334G       6495G   5% /var/lib/docker/overlay2/df51b65f1ba7e1dd54f9029495fe2a7acb021262a6a2f92d8f3c03ac82c5fc1e/merged
overlay                7191G   334G       6495G   5% /var/lib/docker/overlay2/7a84ee8cfaa47f8166a6716c35dbe51487d7f46cab666f543117152db0ef0074/merged
overlay                7191G   334G       6495G   5% /var/lib/docker/overlay2/c6ec81fd0dfe49b4a1f0d8870fb6538a6dd1c350c9885e037a73716b6dee480e/merged
overlay                7191G   334G       6495G   5% /var/lib/docker/overlay2/b8c695c0234119b165dbd55550838577702d16964d5499af4fa1aea1008fc00c/merged
overlay                7191G   334G       6495G   5% /var/lib/docker/overlay2/f2158f254cfa59afe38827932cacd404907c724c5b8859730a2e2777e1a3fe0d/merged
overlay                7191G   334G       6495G   5% /var/lib/docker/overlay2/11ee72f21e307e34e8f7a3594863604559cf4c9dbacbeb28332a30a38757a992/merged
overlay                7191G   334G       6495G   5% /var/lib/docker/overlay2/543c9468588e949e91744d7a2497cfc2e821e067c5ffa2751ccfdfe7a28764e0/merged
overlay                7191G   334G       6495G   5% /var/lib/docker/overlay2/03f4901b0b00e6012c4ad14ad69b5d422214ba2c00d1122598cd440a73001bd1/merged
overlay                7191G   334G       6495G   5% /var/lib/docker/overlay2/a751ff04e1cdbf195b5d5dcba44242af9664504e87458861e57f969883b333de/merged
overlay                7191G   334G       6495G   5% /var/lib/docker/overlay2/1960950f2c6cfa1407feb5effc9aa88c5d6c613ce5fd99a4796ce4d67577c3db/merged
overlay                7191G   334G       6495G   5% /var/lib/docker/overlay2/74d0d0ab694755f6c69bd82b168b983a98f79790ae778671fb50ceb9e98e4afa/merged
overlay                7191G   334G       6495G   5% /var/lib/docker/overlay2/6a5b1f9bebbb14b8aaa80f93ace50d183ae4a7933961e08ab8be07ee9a814ec0/merged
overlay                7191G   334G       6495G   5% /var/lib/docker/overlay2/214b1ff8ad30c4cea6fc3cb03f2c39f07374e6f57ef9a48f4e813dab03745204/merged
overlay                7191G   334G       6495G   5% /var/lib/docker/overlay2/418051a697c467289b8e18cbee5a6990b5732085c0a184f1eb21bd1ca7687006/merged
overlay                7191G   334G       6495G   5% /var/lib/docker/overlay2/85034891f0703020e4622d78e89b92017e4fad79c046794a6c9fa89c16cbb8d9/merged
overlay                7191G   334G       6495G   5% /var/lib/docker/overlay2/92b6734589f1ceff652d17a4eeab95b072a903075841194d8297601ad71e0a5e/merged
overlay                7191G   334G       6495G   5% /var/lib/docker/overlay2/49409bd90d8b517315229f80c5085a2d9e70395333a0d8684d1a9e7b320e0700/merged
overlay                7191G   334G       6495G   5% /var/lib/docker/overlay2/3cffec7936bc14ebc512ab4fa82de5a1ad4522a07e9df1ca6d0bf3337d38098b/merged
overlay                7191G   334G       6495G   5% /var/lib/docker/overlay2/34a64e7a8e0ad4632a260f391c83c8f709cfad1fe0c9674aaef30c3802e86008/merged
overlay                7191G   334G       6495G   5% /var/lib/docker/overlay2/e6b03be90e67d8968e04c60c1737803d6a39e9c6ff407f07aa9cf0128fc24008/merged
overlay                7191G   334G       6495G   5% /var/lib/docker/overlay2/d99ec4e5b89f80c399956f192fbac422ec35a9bf7a41768f92ed83897dd352b2/merged
overlay                7191G   334G       6495G   5% /var/lib/docker/overlay2/a7b1d665783fbe6dbf7595d7b0c8f2b20df499d5ab5b283147464e0ccf847501/merged
overlay                7191G   334G       6495G   5% /var/lib/docker/overlay2/9f6dd99e79626cbcfef5110f82be2a5141dbc90cb8b7dc9ec21d18d0f9df10dc/merged

答案1

du报告来自不同文件系统的文件。我们过去常常du -x看到差异。

答案2

基本上,df只读取超级块并完全信任它。 du读取每个对象并对其进行总结。

如果正在运行的进程保持已删除的文件打开,则该空间仍将被保留并可供查看df,但du将不再在目录树中看到该文件,并将忽略那些保留的块。

如需了解更多信息,请参阅 为什么 DU 和 DF 在 Linux 和 Unix 上显示不同的值

相关内容