linux命令之du
1.du介绍
linux命令du是命令用来查看目录或文件所占用磁盘空间的大小
2.du用法
du [参数] filename|dirname
参数 | 说明 |
-h | 以人类可读的方式显示 |
-s | 显示目录占用的磁盘空间大小,不要显示其下子目录和文件占用的磁盘空间大小 |
-k | 以1024 bytes为单位 |
-m | 以1024 bytes为单位 |
-l(消息L) | 统计硬链接占用磁盘空间的大小 |
-L | 统计符号链接所指向的文件占用的磁盘空间大小 |
--max-depth=N | N是数值,表示目录层数,超过指定层数的目录后,予以忽略 |
3.实例
3.1.以人类可读的方式(K/M/G)显示/etc目录的大小
命令:
du -sh /etc
[root@rhel77 ~]# du -sh /etc
66M /etc
[root@rhel77 ~]#
3.2.统计硬链接占用磁盘空间的大小
命令:
du -l /root
[root@rhel77 ~]# du -l /root
0 /root/110
12 /root/.ssh
0 /root/111
0 /root/3
4 /root/.oracle_jre_usage
16 /root/test
0 /root/back
4 /root/.cache/abrt
4 /root/.cache
0 /root/.config/abrt
0 /root/.config/gconf
4 /root/.config/dconf
0 /root/.config/ibus/bus
0 /root/.config/ibus
4 /root/.config
0 /root/4
4 /root/ztj/test
16 /root/ztj
16 /root/2
8 /root/.dbus/session-bus
8 /root/.dbus
0 /root/.emacs.d
4 /root/z
28 /root/1
112 /root/extundelete-0.2.4/src/.deps
4780 /root/extundelete-0.2.4/src
5244 /root/extundelete-0.2.4
0 /root/z1
16 /root/ztj11
0 /root/testdir
0 /root/.ansible/tmp
0 /root/.ansible
0 /root/.pki/nssdb
0 /root/.pki
635976 /root
[root@rhel77 ~]#
3.3.统计符号链接所指向的文件占用的磁盘空间大小
命令:
du -L /root
[root@rhel77 .pki]# du -L /root
0 /root/110
12 /root/.ssh
0 /root/111
0 /root/3
4 /root/.oracle_jre_usage
8 /root/test
0 /root/back
4 /root/.cache/abrt
4 /root/.cache
112 /root/extundelete/src/.deps
4780 /root/extundelete/src
5244 /root/extundelete
0 /root/.config/abrt
0 /root/.config/gconf
4 /root/.config/dconf
0 /root/.config/ibus/bus
0 /root/.config/ibus
4 /root/.config
0 /root/4
4 /root/ztj/test
16 /root/ztj
16 /root/2
8 /root/.dbus/session-bus
8 /root/.dbus
0 /root/.emacs.d
4 /root/z
28 /root/1
0 /root/z1
16 /root/ztj11
0 /root/testdir
0 /root/.ansible/tmp
0 /root/.ansible
0 /root/.pki/nssdb
0 /root/.pki
635968 /root
[root@rhel77 .pki]#
3.4.查看etc目录及下一级子文件和子目录占用的磁盘容量,并排序
命令:
du -lh /etc --max-depth=1 | sort -nr
[root@rhel77 ~]# du -lh /etc --max-depth=1 | sort -nr
604K /etc/ssh
456K /etc/sysconfig
380K /etc/lvm
332K /etc/sane.d
292K /etc/xdg
244K /etc/vmware-tools
236K /etc/dbus-1
224K /etc/ImageMagick
196K /etc/mail
176K /etc/pam.d
172K /etc/libreport
156K /etc/libvirt
148K /etc/postfix
128K /etc/bash_completion.d
92K /etc/httpd
88K /etc/profile.d
84K /etc/security
80K /etc/speech-dispatcher
80K /etc/logrotate.d
72K /etc/grub.d
68K /etc/X11
68K /etc/openldap
66M /etc
60K /etc/setuptool.d
60K /etc/libibverbs.d
52K /etc/sound
52K /etc/rpm
52K /etc/ppp
48K /etc/rdma
48K /etc/rc.d
44K /etc/cups
40M /etc/selinux
36K /etc/systemd
36K /etc/iproute2
32K /etc/yum.repos.d
32K /etc/yum
32K /etc/php.d
32K /etc/dconf
32K /etc/abrt
28K /etc/rhsm
28K /etc/nginx
28K /etc/NetworkManager
28K /etc/modprobe.d
24K /etc/unbound
24K /etc/mcelog
24K /etc/ipsec.d
24K /etc/fwupd
24K /etc/fonts
20K /etc/samba
20K /etc/pulse
20K /etc/ld.so.conf.d
20K /etc/java
20K /etc/iscsi
20K /etc/gdm
16K /etc/tuned
16K /etc/smartmontools
16K /etc/skel
16K /etc/sasl2
16K /etc/prelink.conf.d
16K /etc/PackageKit
16K /etc/firewalld
16K /etc/cron.daily
16K /etc/audit
16K /etc/audisp
12K /etc/gssproxy
12K /etc/default
12K /etc/cupshelpers
12K /etc/cron.d
12K /etc/avahi
12K /etc/alsa
8.0K /etc/setroubleshoot
8.0K /etc/rwtab.d
8.0K /etc/ras
8.0K /etc/polkit-1
8.0K /etc/oddjobd.conf.d
8.0K /etc/ntp
8.0K /etc/ndctl
8.0K /etc/lsm
8.0K /etc/libnl
8.0K /etc/groff
8.0K /etc/gnome-vfs-2.0
8.0K /etc/festival
8.0K /etc/dnf
8.0K /etc/dhcp
8.0K /etc/depmod.d
8.0K /etc/cron.hourly
7.9M /etc/udev
6.2M /etc/gconf
4.0K /etc/xml
4.0K /etc/wpa_supplicant
4.0K /etc/UPower
4.0K /etc/udisks2
4.0K /etc/sgml
4.0K /etc/rsyslog.d
4.0K /etc/request-key.d
4.0K /etc/qemu-kvm
4.0K /etc/qemu-ga
4.0K /etc/python
4.0K /etc/purple
4.0K /etc/plymouth
4.0K /etc/opt
4.0K /etc/libblockdev
4.0K /etc/kernel
4.0K /etc/hp
4.0K /etc/gss
4.0K /etc/geoclue
4.0K /etc/fcoe
4.0K /etc/dracut.conf.d
4.0K /etc/docker
4.0K /etc/chromium
4.0K /etc/bonobo-activation
4.0K /etc/bluetooth
4.0K /etc/alternatives
3.8M /etc/brltty
1.1M /etc/pki
0 /etc/xinetd.d
0 /etc/tmpfiles.d
0 /etc/terminfo
0 /etc/sysctl.d
0 /etc/sudoers.d
0 /etc/statetab.d
0 /etc/ssl
0 /etc/smrsh
0 /etc/scl
0 /etc/popt.d
0 /etc/pm
0 /etc/pkcs11
0 /etc/oddjob
0 /etc/my.cnf.d
0 /etc/multipath
0 /etc/modules-load.d
0 /etc/maven
0 /etc/libpaper.d
0 /etc/krb5.conf.d
0 /etc/jvm-commmon
0 /etc/jvm
0 /etc/gnupg
0 /etc/glvnd
0 /etc/ghostscript
0 /etc/gdbinit.d
0 /etc/gcrypt
0 /etc/flatpak
0 /etc/firefox
0 /etc/exports.d
0 /etc/egl
0 /etc/dnsmasq.d
0 /etc/cron.weekly
0 /etc/cron.monthly
0 /etc/cifs-utils
0 /etc/chkconfig.d
0 /etc/binfmt.d
[root@rhel77 ~]#