1.概述
du常用于查看占用空间大小。
2.不带参数
默认情况下,du只显示文件夹大小。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
| [root@smart Desktop]# ls -p aa cd.txt.bak2 ls.test test.md wireshark.desktop alias.txt du.txt ls.txt test.md~ cat.txt k.txt ls.txt.bak test.txt cd.txt linux/ test.log test.txt2 cd.txt.bak ls (copy).test~ test.log.bak test.txt3 [root@smart Desktop]# du 1340 ./linux/txt 4 ./linux/h/abcde 8 ./linux/h 4 ./linux/B/A 8 ./linux/B 4 ./linux/.dir 4 ./linux/ss 8 ./linux/test/B 16 ./linux/test 8 ./linux/d 1412 ./linux 1848 . [root@smart Desktop]#
|
3.显示所有文件及文件夹大小
du -a 可以显示所有的文件及文件夹大小
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28
| [root@smart Desktop]# du -a 84 ./alias.txt 8 ./ls.txt 8 ./test.log.bak 8 ./ls.txt.bak 84 ./cd.txt 8 ./du.txt 4 ./test.txt2 4 ./test.txt 0 ./linux/c 4 ./linux/txt/uzip.txt 4 ./linux/txt/su.txt 4 ./linux/test/B/A 8 ./linux/test/B ... 0 ./linux/d/b.c 8 ./test.log 4 ./ls (copy).test~ 1848 . [root@smart Desktop]# [root@smart linux]# cp b.txt k.txt [root@smart linux]# cp b.txt k.txt cp: overwrite `k.txt'? y [root@smart linux]# cp -f b.txt k.txt cp: overwrite `k.txt'? y [root@smart linux]# \cp -f b.txt k.txt [root@smart linux]# alias cp='cp' [root@smart linux]# cp -r b.txt k.txt
|
4.显示容量大小单位
du -m/-b
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32
| [root@smart linux]# du -m 2 ./txt 1 ./h/abcde 1 ./h 1 ./A 1 ./B/A 1 ./B 1 ./.dir 1 ./ss 1 ./abcde 1 ./test/A 1 ./test/B/A 1 ./test/B 1 ./test 1 ./d 2 . [root@smart linux]# du -b 1220718 ./txt 4096 ./h/abcde 8192 ./h 4096 ./A 4096 ./B/A 8192 ./B 4096 ./.dir 4096 ./ss 4096 ./abcde 4096 ./test/A 4096 ./test/B/A 8192 ./test/B 16384 ./test 4126 ./d 1278108 .
|
此处要注意,默认情况下,Linux系统一般都会alias cp为交互模式,可以查看~/.bashrc。
5.以人类可读方式
du -h
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
| [root@smart linux]# du -h 1.4M ./txt 4.0K ./h/abcde 8.0K ./h 4.0K ./A 4.0K ./B/A 8.0K ./B 4.0K ./.dir 4.0K ./ss 4.0K ./abcde 4.0K ./test/A 4.0K ./test/B/A 8.0K ./test/B 16K ./test 8.0K ./d 1.4M .
|
6.不显示0字节大小文件
du -0
1 2
| [root@smart linux]# du -0 1340 ./txt4 ./h/abcde8 ./h4 ./A4 ./B/A8 ./B4 ./.dir4 ./ss4 ./abcde4 ./test/A4 ./test/B/A8 ./test/B16 ./test8 ./d1412 .[root@smart linux]#
|
7.显示最大深度
–max-depth=N,显示几级文件夹的深度
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43
| [root@smart linux]# du --max-depth=1 1340 ./txt 8 ./h 4 ./A 8 ./B 4 ./.dir 4 ./ss 4 ./abcde 16 ./test 8 ./d 1412 . [root@smart linux]# du --max-depth=2 1340 ./txt 4 ./h/abcde 8 ./h 4 ./A 4 ./B/A 8 ./B 4 ./.dir 4 ./ss 4 ./abcde 4 ./test/A 8 ./test/B 16 ./test 8 ./d 1412 . [root@smart linux]# du --max-depth=3 1340 ./txt 4 ./h/abcde 8 ./h 4 ./A 4 ./B/A 8 ./B 4 ./.dir 4 ./ss 4 ./abcde 4 ./test/A 4 ./test/B/A 8 ./test/B 16 ./test 8 ./d 1412 . [root@smart linux]#
|