文章目录
- Linux查看磁盘或目录容量
- 使用df命令查看已挂载磁盘的总容量、使用容量、和剩余容量等信息
- 将系统内的所有特殊文件格式及名称都列出来
- 以KB为单位显示
- 以MB为单位显示
Linux查看磁盘或目录容量
使用df命令查看已挂载磁盘的总容量、使用容量、和剩余容量等信息
###df语法
功能描述:显示磁盘的相关信息
语法
df [选项]
选项及参数
-
-a
,--all
:包含全部的文件系统 -
--block-size=<区块大小>
:以指定的区块大小来显示区块数目 -
-h
,--human-readable
:以可读性较高的方式来显示信息 -
-H
,--si
:与-h参数相同,但是计算时是以1000 Bytes为换算单位而非1024Bytes -
-i
,--inodes
:显示inode的信息 -
-k
,--kilobytes
:指定区块大小为1024字节 -
-l
,--local
:仅显示本地端的文件系统 -
-m
,--megabytes
:指定区块大小为1048576字节 -
--no-sync
:在取得磁盘使用信息前,不要执行sync指令,此为预设值 -
-P
,--portability
:使用POSIX的输出格式 -
--sync
:在取得磁盘使用信息前,先执行sync指令 -
-t<文件类型系统>
,--type=<文件系统类型>
:仅显示指定文件系统类型的磁盘信息 -
-T
,--print-type
:显示文件系统的类型 -
-x<文件系统类型>
,--exclude-type=<文件系统类型>
:不要显示指定文件系统类型的磁盘信息 -
[文件或设备]
:指定磁盘设备
###简单使用
可以直接使用df命令不带任何参数
在 Linux 底下如果 df 没有加任何选项,那么默认会将系统内所有的 (不含特殊内存内的文件系统与 swap) 都以 1 Kbytes 的容量来列出来!
[root@localhost ~]# df
文件系统 1K-块 已用 可用 已用% 挂载点
devtmpfs 485856 0 485856 0% /dev
tmpfs 497872 0 497872 0% /dev/shm
tmpfs 497872 7792 490080 2% /run
tmpfs 497872 0 497872 0% /sys/fs/cgroup
/dev/mapper/centos-root 17811456 1361128 16450328 8% /
/dev/sda1 1038336 139276 899060 14% /boot
tmpfs 99576 0 99576 0% /run/user/0
####查看inodes的使用情况
[root@localhost ~]# df -i
文件系统 Inode 已用(I) 可用(I) 已用(I)% 挂载点
devtmpfs 121464 385 121079 1% /dev
tmpfs 124468 1 124467 1% /dev/shm
tmpfs 124468 734 123734 1% /run
tmpfs 124468 16 124452 1% /sys/fs/cgroup
/dev/mapper/centos-root 8910848 28466 8882382 1% /
/dev/sda1 524288 326 523962 1% /boot
tmpfs 124468 1 124467 1% /run/user/0
将系统内的所有特殊文件格式及名称都列出来
[root@localhost ~]# df -aT
文件系统 类型 1K-块 已用 可用 已用% 挂载点
sysfs sysfs 0 0 0 - /sys
proc proc 0 0 0 - /proc
devtmpfs devtmpfs 485856 0 485856 0% /dev
securityfs securityfs 0 0 0 - /sys/kernel/security
tmpfs tmpfs 497872 0 497872 0% /dev/shm
devpts devpts 0 0 0 - /dev/pts
tmpfs tmpfs 497872 7792 490080 2% /run
tmpfs tmpfs 497872 0 497872 0% /sys/fs/cgroup
cgroup cgroup 0 0 0 - /sys/fs/cgroup/systemd
pstore pstore 0 0 0 - /sys/fs/pstore
cgroup cgroup 0 0 0 - /sys/fs/cgroup/pids
cgroup cgroup 0 0 0 - /sys/fs/cgroup/freezer
cgroup cgroup 0 0 0 - /sys/fs/cgroup/net_cls,net_prio
cgroup cgroup 0 0 0 - /sys/fs/cgroup/perf_event
cgroup cgroup 0 0 0 - /sys/fs/cgroup/memory
cgroup cgroup 0 0 0 - /sys/fs/cgroup/hugetlb
cgroup cgroup 0 0 0 - /sys/fs/cgroup/cpu,cpuacct
cgroup cgroup 0 0 0 - /sys/fs/cgroup/devices
cgroup cgroup 0 0 0 - /sys/fs/cgroup/cpuset
cgroup cgroup 0 0 0 - /sys/fs/cgroup/blkio
configfs configfs 0 0 0 - /sys/kernel/config
/dev/mapper/centos-root xfs 17811456 1361544 16449912 8% /
selinuxfs selinuxfs 0 0 0 - /sys/fs/selinux
systemd-1 - - - - - /proc/sys/fs/binfmt_misc
debugfs debugfs 0 0 0 - /sys/kernel/debug
hugetlbfs hugetlbfs 0 0 0 - /dev/hugepages
mqueue mqueue 0 0 0 - /dev/mqueue
/dev/sda1 xfs 1038336 139276 899060 14% /boot
tmpfs tmpfs 99576 0 99576 0% /run/user/0
binfmt_misc binfmt_misc 0 0 0 - /proc/sys/fs/binfmt_misc
####将 /etc 底下的可用的磁盘容量以易读的容量格式显示
[root@localhost ~]# df -h /etc
文件系统 容量 已用 可用 已用% 挂载点
/dev/mapper/centos-root 17G 1.3G 16G 8% /
####使用合适的单位显示
[root@localhost ~]# df -h
文件系统 容量 已用 可用 已用% 挂载点
devtmpfs 475M 0 475M 0% /dev
tmpfs 487M 0 487M 0% /dev/shm
tmpfs 487M 7.7M 479M 2% /run
tmpfs 487M 0 487M 0% /sys/fs/cgroup
/dev/mapper/centos-root 17G 1.3G 16G 8% /
/dev/sda1 1014M 137M 878M 14% /boot
tmpfs 98M 0 98M 0% /run/user/0
以KB为单位显示
[root@localhost ~]# df -k
文件系统 1K-块 已用 可用 已用% 挂载点
devtmpfs 485856 0 485856 0% /dev
tmpfs 497872 0 497872 0% /dev/shm
tmpfs 497872 7792 490080 2% /run
tmpfs 497872 0 497872 0% /sys/fs/cgroup
/dev/mapper/centos-root 17811456 1361128 16450328 8% /
/dev/sda1 1038336 139276 899060 14% /boot
tmpfs 99576 0 99576 0% /run/user/0
以MB为单位显示
[root@localhost ~]# df -m
文件系统 1M-块 已用 可用 已用% 挂载点
devtmpfs 475 0 475 0% /dev
tmpfs 487 0 487 0% /dev/shm
tmpfs 487 8 479 2% /run
tmpfs 487 0 487 0% /sys/fs/cgroup
/dev/mapper/centos-root 17394 1330 16065 8% /
/dev/sda1 1014 137 878 14% /boot
tmpfs 98 0 98 0% /run/user/0
##使用du命令查看某个目录或文件所占空间的大小
###du语法
功能说明:显示目录或文件所占用的磁盘空间
语法
du [选项] [文件或者目录名]
选项及参数
-
-a
,-all
:显示目录中个别文件的大小 -
-b
,-bytes
:显示目录或文件大小,以byte为单位 -
-c
,--toal
:除了显示个别目录或文件的大小外,同时也显示所有目录或文件的总和 -
-D
,--dereference-args
:显示指定符号连接的源文件大小 -
-h
,--human-readable
:以K,M,G为单位,提高信息的可读性 -
-H
,--si
:与-h参数相同,但是K,M,G是以1000为换算单位 -
-k
,--kilobytes
:以1024bytes为单位 -
-l
,--count-links
:重新计算硬件连接的文件 -
-L<符号连接>
,--dereference<符号连接>
:显示选项中所指定符号连接的源文件大小 -
-m
,--megabytes
:以MB为单位 -
-s
,--summarize
:仅显示总计 -
-S
,--separate-dirs
:显示个别目录的大小时,并不含其子目录的大小 -
-x
,--one-file-xystem
:以一开始处理时的文件系统为准,若遇上其它不同的文件系统目录则略过 -
-X<文件>
,--exclude-from=<文件>
:在<文件>指定目录或文件 -
--exclude=<目录或文件>
:略过指定的目录或文件 -
--max-depth=<目录层数>
:超过指定层数的目录后,予以忽略
###简单使用
[root@localhost ~]# du /root
0 /root/dir
4 /root/root
4 /root/test/root
4 /root/test
0 /root/.pki/nssdb
0 /root/.pki
48 /root
####列出全部文件和目录
[root@localhost ~]# du -a /root
4 /root/.bash_logout
4 /root/.bash_profile
4 /root/.bashrc
4 /root/.cshrc
4 /root/.tcshrc
4 /root/anaconda-ks.cfg
12 /root/.bash_history
0 /root/dir/test1.txt
0 /root/dir/test2.txt
0 /root/dir/test.txt
0 /root/dir
0 /root/root/test2.txt
4 /root/root/test.txt
4 /root/root
4 /root/test/root/test.txt
4 /root/test/root
4 /root/test
4 /root/test.txt.bz2
0 /root/.pki/nssdb
0 /root/.pki
48 /root
####以KB为单位输出
[root@localhost ~]# du -k /root
0 /root/dir
4 /root/root
4 /root/test/root
4 /root/test
0 /root/.pki/nssdb
0 /root/.pki
48 /root
####以MB为单位输出
[root@localhost ~]# du -m /root
0 /root/dir
1 /root/root
1 /root/test/root
1 /root/test
0 /root/.pki/nssdb
0 /root/.pki
1 /root
####自动选择输出单位
[root@localhost ~]# du -h /root
0 /root/dir
4.0K /root/root
4.0K /root/test/root
4.0K /root/test
0 /root/.pki/nssdb
0 /root/.pki
48K /root