以下几个命令在操作磁盘时容易搞混,特此梳理一下各自的使用场景
df
作用
df - report file system disk space usage
用于展示文件系统的磁盘使用情况
示例
[root@suhw ~]# df -hT
Filesystem Type Size Used Avail Use% Mounted on
/dev/mapper/centos-root xfs 17G 1013M 16G 6% /
devtmpfs devtmpfs 3.9G 0 3.9G 0% /dev
tmpfs tmpfs 3.9G 0 3.9G 0% /dev/shm
tmpfs tmpfs 3.9G 41M 3.8G 2% /run
tmpfs tmpfs 3.9G 0 3.9G 0% /sys/fs/cgroup
/dev/sda1 xfs 1014M 145M 870M 15% /boot
tmpfs tmpfs 783M 0 783M 0% /run/user/0
常用参数
-h, --human-readable 用易读的方式打印大小 (e.g., 1K 234M 2G)
-T, --print-type 打印文件系统类型
du
作用
du - estimate file space usage
用于估计文件空间使用情况
示例
[root@suhw ~]# du -h file.txt
4.0K file.txt
常用参数
-h, --human-readable 用易读的方式打印大小 (e.g., 1K 234M 2G)
fdisk
作用
fdisk - manipulate disk partition table
操作磁盘分区表
示例
- 打印磁盘分区信息
[root@suhw ~]# fdisk -l
Disk /dev/sda: 85.9 GB, 85899345920 bytes, 167772160 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk label type: dos
Disk identifier: 0x000d8731
Device Boot Start End Blocks Id System
/dev/sda1 * 2048 2099199 1048576 83 Linux
/dev/sda2 2099200 41943039 19921920 8e Linux LVM
Disk /dev/mapper/centos-root: 18.2 GB, 18249416704 bytes, 35643392 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk /dev/mapper/centos-swap: 2147 MB, 2147483648 bytes, 4194304 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
- 对设备进行交互式操作
[root@suhw ~]# fdisk /dev/sda
Welcome to fdisk (util-linux 2.23.2).
Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.
Device does not contain a recognized partition table
Building a new DOS disklabel with disk identifier 0x9009d40d.
Command (m for help): m
Command action
a toggle a bootable flag
b edit bsd disklabel
c toggle the dos compatibility flag
d delete a partition
g create a new empty GPT partition table
G create an IRIX (SGI) partition table
l list known partition types
m print this menu
n add a new partition
o create a new empty DOS partition table
p print the partition table
q quit without saving changes
s create a new empty Sun disklabel
t change a partition's system id
u change display/entry units
v verify the partition table
w write table to disk and exit
x extra functionality (experts only)
根据提示信息对磁盘分区进行后续的操作
lsblk
作用
lsblk - list block devices
列出所有可用块设备信息,同时显示他们之间的依赖关系。
示例
[root@suhw ~]# lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sda 8:0 0 80G 0 disk
├─sda1 8:1 0 1G 0 part /boot
└─sda2 8:2 0 19G 0 part
├─centos-root 253:0 0 17G 0 lvm /
└─centos-swap 253:1 0 2G 0 lvm [SWAP]
字段解释
| 字段 | 解释 |
|---|---|
| NAME | 块设备名 |
| MAJ:MIN | 主要和次要设备号 |
| RM | 是否是可移动设备 |
| SIZE | 设备的容量大小信息 |
| RO | 是否为只读 |
| TYPE | 显示块设备类型 disk磁盘,part分区,lvm逻辑卷,room只读存储 |
| MOUNTPOINT | 设置挂载的挂载点 |
常用参数
[root@study ~]# lsblk [-dfimpt] [device]
选项与参数:
-d :仅列出磁盘本身,并不会列出该磁盘的分区数据
-f :同时列出该磁盘内的文件系统名称
-i :使用 ASCII 的线段输出,不要使用复杂的编码 (再某些环境下很有用)
-m :同时输出该设备在 /dev 下面的权限数据 (rwx 的数据)
-p :列出该设备的完整文件名!而不是仅列出最后的名字而已。
-t :列出该磁盘设备的详细数据,包括磁盘伫列机制、预读写的数据量大小等
blkid
作用
blkid - locate/print block device attributes
打印块设备属性
示例
查看设备的uuid以及type等信息
[root@suhw ~]# blkid
/dev/mapper/centos-root: UUID="a6273829-ea65-4d66-8975-e57bda2c45a3" TYPE="xfs"
/dev/sda2: UUID="eJxxnr-dqUB-oZlr-j6Hr-MUWl-oJs6-JUBALe" TYPE="LVM2_member"
/dev/sda1: UUID="20c37421-fe58-4a0e-98ef-10acf395ffbf" TYPE="xfs"
/dev/mapper/centos-swap: UUID="5bc2d0fa-6abd-4e60-a7ea-743ef62dff65" TYPE="swap"
parted
作用
parted - a partition manipulation program
用于操作分区的程序
示例
通过parted查看分区信息,可看除分区格式是msdos(MBR)
[root@suhw ~]# parted /dev/sda print
Model: QEMU QEMU HARDDISK (scsi)
Disk /dev/sda: 85.9GB
Sector size (logical/physical): 512B/512B
Partition Table: msdos
Disk Flags:
Number Start End Size Type File system Flags
1 1049kB 1075MB 1074MB primary xfs boot
2 1075MB 21.5GB 20.4GB primary lvm
3 21.5GB 23.6GB 2147MB primary lvm
915

被折叠的 条评论
为什么被折叠?



