du
即Disk Usage,用来获取磁盘的使用情况的,下面分别介绍几个常用的命令参数
1. 查看给定目录树各个目录的使用情况
[root@localhost redis-5.0.4]# pwd
/root/redis-5.0.4
[root@localhost redis-5.0.4]# du
44 ./deps/hiredis/adapters
40 ./deps/hiredis/examples
1296 ./deps/hiredis
368 ./deps/jemalloc/bin
88 ./deps/jemalloc/build-aux
324 ./deps/jemalloc/doc
684 ./deps/jemalloc/include/jemalloc/internal
2. 增加-h
选项,磁盘的使用转化为容易理解的大小表示方式
[root@localhost redis-5.0.4]# du -h
44K ./deps/hiredis/adapters
40K ./deps/hiredis/examples
1.3M ./deps/hiredis
368K ./deps/jemalloc/bin
88K ./deps/jemalloc/build-aux
324K ./deps/jemalloc/doc
684K ./deps/jemalloc/include/jemalloc/internal
768K ./deps/jemalloc/include/jemalloc
3. -s
用来获取特定目录使用的总空间
[root@localhost redis-5.0.4]# pwd
/root/redis-5.0.4
[root@localhost redis-5.0.4]# du -sh .
117M .
4. -a
显示所有的文件和目录的磁盘使用情况
默认情况下只显示目录的,不包含文件
[root@localhost redis-5.0.4]# du -ah
4.0K ./.gitignore
100K ./00-RELEASENOTES
4.0K ./BUGS
4.0K ./CONTRIBUTING
4.0K ./COPYING
4.0K ./INSTALL
8.0K ./MANIFESTO
4.0K ./Makefile
24K ./README.md
4.0K ./deps/Makefile
8.0K ./deps/README.md
4.0K ./deps/hiredis/.gitignore
4.0K ./deps/hiredis/.travis.yml
8.0K ./deps/hiredis/CHANGELOG.md
5. -k
控制显示制输出的磁盘使用k为单位
[root@localhost redis-5.0.4]# du -sk .
119504 .
[root@localhost redis-5.0.4]#
6. -m
控制显示输出的磁盘使用M为单位
[root@localhost /]# du -m -d 1 /
126 /boot
0 /dev
du: cannot access ‘/proc/40904/task/40904/fd/3’: No such file or directory
du: cannot access ‘/proc/40904/task/40904/fdinfo/3’: No such file or directory
du: cannot access ‘/proc/40904/fd/4’: No such file or directory
du: cannot access ‘/proc/40904/fdinfo/4’: No such file or directory
0 /proc
9 /run
0 /sys
41 /etc
119 /root
1608 /var
9 /tmp
4114 /usr
268 /home
0 /media
0 /mnt
0 /opt
0 /srv
6290 /
7. -c
用来输出给定目录的总的使用情况,结果在最后两行显示
[root@localhost redis-5.0.4]# du -ch .
...
8.0K ./utils/hashtable
12K ./utils/hyperloglog
20K ./utils/lru
20K ./utils/releasetools
136K ./utils
117M .
117M total
[root@localhost redis-5.0.4]#
8. --exclude
用来剔除符合给定pattern的文件
[root@localhost integration]# ll
total 100
-rw-rw-r--. 1 root root 1302 Mar 18 12:21 aof-race.tcl
-rw-rw-r--. 1 root root 8857 Mar 18 12:21 aof.tcl
-rw-rw-r--. 1 root root 2079 Mar 18 12:21 block-repl.tcl
-rw-rw-r--. 1 root root 1305 Mar 18 12:21 convert-zipmap-hash-on-load.tcl
-rw-rw-r--. 1 root root 824 Mar 18 12:21 logging.tcl
-rw-rw-r--. 1 root root 2626 Mar 18 12:21 psync2-reg.tcl
-rw-rw-r--. 1 root root 9394 Mar 18 12:21 psync2.tcl
-rw-rw-r--. 1 root root 4335 Mar 18 12:21 rdb.tcl
-rw-rw-r--. 1 root root 6018 Mar 18 12:21 redis-cli.tcl
-rw-rw-r--. 1 root root 3170 Mar 18 12:21 replication-2.tcl
-rw-rw-r--. 1 root root 5036 Mar 18 12:21 replication-3.tcl
-rw-rw-r--. 1 root root 5194 Mar 18 12:21 replication-4.tcl
-rw-rw-r--. 1 root root 5032 Mar 18 12:21 replication-psync.tcl
-rw-rw-r--. 1 root root 11539 Mar 18 12:21 replication.tcl
[root@localhost integration]# du -ah --exclude="redis*" .
4.0K ./aof-race.tcl
12K ./aof.tcl
4.0K ./block-repl.tcl
4.0K ./convert-zipmap-hash-on-load.tcl
4.0K ./logging.tcl
4.0K ./psync2-reg.tcl
12K ./psync2.tcl
8.0K ./rdb.tcl
4.0K ./replication-2.tcl
8.0K ./replication-3.tcl
8.0K ./replication-4.tcl
8.0K ./replication-psync.tcl
12K ./replication.tcl
96K .
[root@localhost integration]#
9 --time
输出文件或目录的修改时间
[root@localhost integration]# du -ha --time .
4.0K 2019-03-18 12:21 ./aof-race.tcl
12K 2019-03-18 12:21 ./aof.tcl
4.0K 2019-03-18 12:21 ./block-repl.tcl
4.0K 2019-03-18 12:21 ./convert-zipmap-hash-on-load.tcl
4.0K 2019-03-18 12:21 ./logging.tcl
4.0K 2019-03-18 12:21 ./psync2-reg.tcl
12K 2019-03-18 12:21 ./psync2.tcl
8.0K 2019-03-18 12:21 ./rdb.tcl
8.0K 2019-03-18 12:21 ./redis-cli.tcl
4.0K 2019-03-18 12:21 ./replication-2.tcl
8.0K 2019-03-18 12:21 ./replication-3.tcl
8.0K 2019-03-18 12:21 ./replication-4.tcl
8.0K 2019-03-18 12:21 ./replication-psync.tcl
12K 2019-03-18 12:21 ./replication.tcl
104K 2019-03-18 12:21 .
10 -d
控制遍历子目录的深度
[root@localhost redis-5.0.4]# du -h -d 1 .
65M ./deps
52M ./src
800K ./tests
136K ./utils
117M .
[root@localhost redis-5.0.4]#
更深入的了解可以直接通过du的man文件了解