du 命令用於顯示每一個文件和目錄使用磁盤空間大小,du 會顯示指定的目錄或文件所佔用的磁盤空間大小。還能夠利用 du 命令,能夠快速的查找 Linux 下的大目錄。centos
du [OPTION]... [FILE]...
-a #顯示目錄中全部文件的大小 -b #顯示目錄或文件大小時,以byte爲單位。 -c #除了顯示個別目錄或文件的大小外,同時也顯示全部目錄或文件的總和 -D #顯示指定符號鏈接的源文件大小 -h #以K,M,G爲單位,提升可讀性 -H #與-h參數相同,但以1000爲換算單位 -k #以1024 bytes爲單位 -l #重複計算硬件鏈接的文件 -L<符號鏈接> #顯示選項中所指定符號鏈接的源文件大小 -m #以1MB爲單位 -s #只顯示總和 -S #顯示指定目錄的大小,可是不顯示其子目錄 --exclude=<目錄或文件> #忽略指定的目錄或文件 --max-depth=<目錄層數> #超過指定層數的目錄後,忽略 --help #打印幫助信息 --version #打印版本信息
顯示目錄或者文件所佔用的磁盤空間centos7
[root@centos7 testdir]# du 0 ./dir 28 . [root@centos7 testdir]# du -h *.gz 4.0K cest.txt.gz 4.0K cuttest.txt.gz 4.0K mingongge1.txt.gz 4.0K mingongge2.txt.gz 4.0K mingongge.txt.md5.gz 4.0K sort.cut.txt.gz [root@centos7 testdir]# du -a 4 ./cest.txt.gz 4 ./cuttest.txt.gz 4 ./mingongge1.txt.gz 4 ./mingongge2.txt.gz 4 ./mingongge.txt.md5.gz 4 ./sort.cut.txt.gz 0 ./dir 0 ./file 4 ./mingongge.zip 28 .
顯示指定文件所佔的磁盤空間3d
[root@centos7 ~]# du test.txt 4 test.txt [root@centos7 ~]# du -h test.txt 4.0K test.txt
查看大目錄code
[root@centos7 ~]# du -h --max-depth=1 0 ./.pki 38M ./goinception 46M ./httpd-2.4.46 28K ./testdir 114M . [root@centos7 ~]# du -h --max-depth=1 |sort -nr 114M . 46M ./httpd-2.4.46 38M ./goinception 28K ./testdir 0 ./.pki