du命令

du命令(磁盘使用情况)用于报告目录的大小及其中的内容。此命令通常用作快速查明正在使用哪些文件并占用您大部分磁盘空间的方法。

df命令示例

df-未传递任何参数

[john@centos ~]$ df
Filesystem           1K-blocks      Used Available Use% Mounted on
/dev/mapper/vg_centos-lv_root
                       6748936   3192592   3213512  50% /
tmpfs                   515368        80    515288   1% /dev/shm
/dev/sda1               495844     73013    397231  16% /boot
/dev/sdb1               287782     10287    262637   4% /test1
/dev/sdb2               295555     10287    270007   4% /test2
/dev/sdb3               295555     10287    270007   4% /test3
/dev/sdb5               295561     10287    270014   4% /test4
/dev/sdb6               295561     10287    270014   4% /test5
/dev/sdb7               295561     10287    270014   4% /test6
/dev/sdb8               264445     10287    240505   5% /test7
/dev/sr0               3626176   3626176         0
100% /media/CentOS_6.3_Final

显示总计大小

[john@centos ~]$ df --total
Filesystem           1K-blocks      Used Available Use% Mounted on
/dev/mapper/vg_centos-lv_root
                       6748936   3192076   3214028  50% /
tmpfs                   515368        80    515288   1% /dev/shm
/dev/sda1               495844     73013    397231  16% /boot
/dev/sdb1               287782     10287    262637   4% /test1
/dev/sdb2               295555     10287    270007   4% /test2
/dev/sdb3               295555     10287    270007   4% /test3
/dev/sdb5               295561     10287    270014   4% /test4
/dev/sdb6               295561     10287    270014   4% /test5
/dev/sdb7               295561     10287    270014   4% /test6
/dev/sdb8               264445     10287    240505   5% /test7
/dev/sr0               3626176   3626176         0
100% /media/CentOS_6.3_Final
total                 13416344   6963354   5979745  54%

转换单位,便于人阅读

[john@centos ~]$ df --total -h
Filesystem            Size  Used Avail Use% Mounted on
/dev/mapper/vg_centos-lv_root
                      6.5G  3.1G  3.1G  50% /
tmpfs                 504M   80K  504M   1% /dev/shm
/dev/sda1             485M   72M  388M  16% /boot
/dev/sdb1             282M   11M  257M   4% /test1
/dev/sdb2             289M   11M  264M   4% /test2
/dev/sdb3             289M   11M  264M   4% /test3
/dev/sdb5             289M   11M  264M   4% /test4
/dev/sdb6             289M   11M  264M   4% /test5
/dev/sdb7             289M   11M  264M   4% /test6
/dev/sdb8             259M   11M  235M   5% /test7
/dev/sr0              3.5G  3.5G     0 100% /media/CentOS_6.3_Final
total                  13G  6.7G  5.8G  54%

只查看某个文件系统的磁盘使用情况

[john@centos ~]$ df -h /test1
Filesystem            Size  Used Avail Use% Mounted on
/dev/sdb1             282M   11M  257M   4% /test1

显示文件系统的类型

[john@centos ~]$ df --total -h -T
Filesystem    Type    Size  Used Avail Use% Mounted on
/dev/mapper/vg_centos-lv_root
              ext4    6.5G  3.1G  3.1G  50% /
tmpfs        tmpfs    504M   84K  504M   1% /dev/shm
/dev/sda1     ext4    485M   72M  388M  16% /boot
/dev/sdb1     ext3    282M   11M  257M   4% /test1
/dev/sdb2     ext3    289M   11M  264M   4% /test2
/dev/sdb3     ext3    289M   11M  264M   4% /test3
/dev/sdb5     ext3    289M   11M  264M   4% /test4
/dev/sdb6     ext3    289M   11M  264M   4% /test5
/dev/sdb7     ext3    289M   11M  264M   4% /test6
/dev/sdb8     ext3    259M   11M  235M   5% /test7
/dev/sr0   iso9660    3.5G  3.5G     0 100% /media/CentOS_6.3_Final
total            -     13G  6.7G  5.8G  54%
df和du命令

使用df和du命令显示文件和文件系统利用率。

df命令-报告文件系统磁盘空间使用情况

df命令用于显示文件系统中可用的磁盘空间量。如果没有参数传递给df命令,则将显示当前已安装文件系统的所有文件系统信息。默认情况下,显示的磁盘空间为1K块大小。如果为df命令提供文件系统的名称,则仅会报告该信息。有许多参数/选项可以传递。

du命令示例

基本用法

显示目录/test1的大小

[root@centos test1]# du /test1
12	/test1/lost+found
21	/test1

-h标志用于以人类可读格式(K,M,G ...)显示文件大小

[root@centos test1]# du -hs /test1
21K	/test1

john@john-desktop:~$ du -hs ~john 
53G	/home/john
日期:2019-04-29 03:17:33 来源:oir作者:oir