du会把指定目录下所有文件、目录、目录下的文件都统计。是建立在文件系统能看到的的确确是有这样一些文件的基础上的。也就是说我们能在文件系统里面看到的文件才会被du统计。

df命令可以获取硬盘被占用了多少空间,目前还剩下多少空间等信息,它也可以显示所有文件系统对i节点和磁盘块的使用情况。

常用操作

# du -h --max-depth=1
18G	./caomall_bak_2018_1120
17G	./caomall
35G	.

# du -h --max-depth=2
80M	./caomall_bak_2018_1120/installed
16M	./caomall_bak_2018_1120/logs
20K	./caomall_bak_2018_1120/pids
100K	./caomall_bak_2018_1120/seahub-data
247M	./caomall_bak_2018_1120/seafile-pro-server-6.2.9
168K	./caomall_bak_2018_1120/ccnet
28K	./caomall_bak_2018_1120/conf
17G	./caomall_bak_2018_1120/seafile-data
4.4M	./caomall_bak_2018_1120/pro-data
18G	./caomall_bak_2018_1120
80M	./caomall/installed
16M	./caomall/logs
20K	./caomall/pids
100K	./caomall/seahub-data
247M	./caomall/seafile-pro-server-6.2.9
176K	./caomall/ccnet
28K	./caomall/conf
17G	./caomall/seafile-data
4.4M	./caomall/pro-data
17G	./caomall
35G	.

# du -h --max-depth=2 /opt/caomall
80M	/opt/caomall/installed
16M	/opt/caomall/logs
20K	/opt/caomall/pids
32K	/opt/caomall/seahub-data/avatars
64K	/opt/caomall/seahub-data/thumbnail
100K	/opt/caomall/seahub-data
47M	/opt/caomall/seafile-pro-server-6.2.9/seafile
708K	/opt/caomall/seafile-pro-server-6.2.9/upgrade
852K	/opt/caomall/seafile-pro-server-6.2.9/seahub-extra
98M	/opt/caomall/seafile-pro-server-6.2.9/seahub
68M	/opt/caomall/seafile-pro-server-6.2.9/pro
132K	/opt/caomall/seafile-pro-server-6.2.9/create-db
34M	/opt/caomall/seafile-pro-server-6.2.9/runtime
247M	/opt/caomall/seafile-pro-server-6.2.9
16K	/opt/caomall/ccnet/OrgMgr
12K	/opt/caomall/ccnet/misc
36K	/opt/caomall/ccnet/GroupMgr
100K	/opt/caomall/ccnet/PeerMgr
176K	/opt/caomall/ccnet
28K	/opt/caomall/conf
8.0K	/opt/caomall/seafile-data/httptemp
4.0K	/opt/caomall/seafile-data/tmpfiles
17G	/opt/caomall/seafile-data/storage
300K	/opt/caomall/seafile-data/library-template
4.0K	/opt/caomall/seafile-data/commits
4.0K	/opt/caomall/seafile-data/fs
17G	/opt/caomall/seafile-data
204K	/opt/caomall/pro-data/search
4.4M	/opt/caomall/pro-data
17G	/opt/caomall

# df -h
文件系统        容量  已用  可用 已用% 挂载点
/dev/vda1        99G   41G   53G   44% /
devtmpfs        3.9G     0  3.9G    0% /dev
tmpfs           3.9G     0  3.9G    0% /dev/shm
tmpfs           3.9G  460K  3.9G    1% /run
tmpfs           3.9G     0  3.9G    0% /sys/fs/cgroup
tmpfs           783M     0  783M    0% /run/user/0

# du -h ./seahub.db 
1.5M	./seahub.db

小结:想统计全部的可以使用

df -h

想统计具体文件夹或者文件的,可以使用

du -h --max-depth=1

默认是所有,可以指定深度,1或者2就够了

可以查看根目录的使用情况

# du  -h --max-depth=1 /