Linux磁盘空间管理是系统运维中的核心环节,它直接影响到系统的稳定运行、数据的安全性和业务的连续性。
通过实施有效的磁盘空间管理策略,系统管理员可以确保系统的高效运作,满足不断变化的业务需求,并为用户提供可靠的服务。
因此,对Linux磁盘空间管理的重视和精通对于任何企业的IT运营都属于核心业务。
Linux df命令用于显示文件系统的磁盘空间使用情况。以下是一些常用的df命令参数:
这些参数可以根据需要组合使用,例如,要以人类可读的格式查看所有文件系统的磁盘空间使用情况,包括 inode 使用信息,可以使用以下命令:
df -ahi
请注意,不同的Linux发行版可能会有一些细微的差异,部分参数可能在某些版本中不可用。所以,在实际环境中,我们通常会先查看当前版本信息。
接下来我们会对DF命令参数进行实际演示:
df -a
df -h
mirror@Ubuntu22:~$ df -h
Filesystem Size Used Avail Use% Mounted on
rootfs 237G 91G 147G 39% /
none 237G 91G 147G 39% /dev
none 237G 91G 147G 39% /run
none 237G 91G 147G 39% /run/lock
none 237G 91G 147G 39% /run/shm
none 237G 91G 147G 39% /run/user
tmpfs 237G 91G 147G 39% /sys/fs/cgroup
C:\ 237G 91G 147G 39% /mnt/c
D:\ 1.9T 301M 1.9T 1% /mnt/d
E:\ 1.9T 35G 1.8T 2% /mnt/e
mirror@Ubuntu22:~$
df -H
使用千字节(KB)作为块大小单位来显示文件系统大小。
df -k
mirror@Ubuntu22:~$ df -k
Filesystem 1K-blocks Used Available Use% Mounted on
rootfs 247655464 94374736 153280728 39% /
none 247655464 94374736 153280728 39% /dev
none 247655464 94374736 153280728 39% /run
none 247655464 94374736 153280728 39% /run/lock
none 247655464 94374736 153280728 39% /run/shm
none 247655464 94374736 153280728 39% /run/user
tmpfs 247655464 94374736 153280728 39% /sys/fs/cgroup
C:\ 247655464 94374736 153280728 39% /mnt/c
D:\ 1953513468 307968 1953205500 1% /mnt/d
E:\ 1953513468 36510556 1917002912 2% /mnt/e
df -m
mirror@Ubuntu22:~$ df -m
Filesystem 1M-blocks Used Available Use% Mounted on
rootfs 241852 92163 149689 39% /
none 241852 92163 149689 39% /dev
none 241852 92163 149689 39% /run
none 241852 92163 149689 39% /run/lock
none 241852 92163 149689 39% /run/shm
none 241852 92163 149689 39% /run/user
tmpfs 241852 92163 149689 39% /sys/fs/cgroup
C:\ 241852 92163 149689 39% /mnt/c
D:\ 1907728 301 1907428 1% /mnt/d
E:\ 1907728 35655 1872074 2% /mnt/e
df -l
用df -l 和df -m 比较久比较明显:
df -i
mirror@Ubuntu22:~$ df -i
Filesystem Inodes IUsed IFree IUse% Mounted on
rootfs 999 -999001 1000000 - /
none 999 -999001 1000000 - /dev
none 999 -999001 1000000 - /run
none 999 -999001 1000000 - /run/lock
none 999 -999001 1000000 - /run/shm
none 999 -999001 1000000 - /run/user
tmpfs 999 -999001 1000000 - /sys/fs/cgroup
C:\ 999 -999001 1000000 - /mnt/c
D:\ 999 -999001 1000000 - /mnt/d
E:\ 999 -999001 1000000 - /mnt/e
df -T
我们的演示主机有wslfs、tmpfs、drvfs三种文件系统
mirror@Ubuntu22:~$ df -T
Filesystem Type 1K-blocks Used Available Use% Mounted on
rootfs wslfs 247655464 94378312 153277152 39% /
none tmpfs 247655464 94378312 153277152 39% /dev
none tmpfs 247655464 94378312 153277152 39% /run
none tmpfs 247655464 94378312 153277152 39% /run/lock
none tmpfs 247655464 94378312 153277152 39% /run/shm
none tmpfs 247655464 94378312 153277152 39% /run/user
tmpfs tmpfs 247655464 94378312 153277152 39% /sys/fs/cgroup
C:\ drvfs 247655464 94378312 153277152 39% /mnt/c
D:\ drvfs 1953513468 307968 1953205500 1% /mnt/d
E:\ drvfs 1953513468 36510556 1917002912 2% /mnt/e
过滤一下tmpfs的文件系统类型
df -T --type=tmpfs
mirror@Ubuntu22:~$ df -T --type=tmpfs
Filesystem Type 1K-blocks Used Available Use% Mounted on
none tmpfs 247655464 94379132 153276332 39% /dev
none tmpfs 247655464 94379132 153276332 39% /run
none tmpfs 247655464 94379132 153276332 39% /run/lock
none tmpfs 247655464 94379132 153276332 39% /run/shm
none tmpfs 247655464 94379132 153276332 39% /run/user
tmpfs tmpfs 247655464 94379132 153276332 39% /sys/fs/cgroup
mirror@Ubuntu22:~$
df -x tmpfs
或者
df --exclude-type=tmpfs
mirror@Ubuntu22:~$ df --exclude-type=tmpfs
Filesystem 1K-blocks Used Available Use% Mounted on
rootfs 247655464 94371068 153284396 39% /
C:\ 247655464 94371068 153284396 39% /mnt/c
D:\ 1953513468 307968 1953205500 1% /mnt/d
E:\ 1953513468 36510556 1917002912 2% /mnt/e
df -t tmpfs
或者
df --type=tmpfs
mirror@Ubuntu22:~$ df -t tmpfs
Filesystem 1K-blocks Used Available Use% Mounted on
none 247655464 94367632 153287832 39% /dev
none 247655464 94367632 153287832 39% /run
none 247655464 94367632 153287832 39% /run/lock
none 247655464 94367632 153287832 39% /run/shm
none 247655464 94367632 153287832 39% /run/user
tmpfs 247655464 94367632 153287832 39% /sys/fs/cgroup
mirror@Ubuntu22:~$
df -h file /etc
df -h file /etc --output=used
以上希望帮助大家掌握df命令的常用方法。