Xiaohan explains Linux commonly used commands - lsblk

Foreword:

        The lsblk command is  used to list the information of all available block devices, and can also display the dependencies between them, but it will not list the information of the RAM disk. Block devices include hard drives, flash drives, cd-ROMs, and so on. The lsblk command is included in the util-linux-ng package, which is now renamed util-linux. This package comes with several other tools, such as dmesg. To install lsblk, download the util-linux package here. Fedora users can sudo yum install -y util-linux-nginstall the package through commands .

1) Options

-a, --all            显示所有设备。
-b, --bytes          以bytes方式显示设备大小。
-d, --nodeps         不显示 slaves 或 holders。
-D, --discard        print discard capabilities。
-e, --exclude <list> 排除设备 (default: RAM disks)。
-f, --fs             显示文件系统信息。
-h, --help           显示帮助信息。
-i, --ascii          use ascii characters only。
-m, --perms          显示权限信息。
-l, --list           使用列表格式显示。
-n, --noheadings     不显示标题。
-o, --output <list>  输出列。
-P, --pairs          使用key="value"格式显示。
-r, --raw            使用原始格式显示。
-t, --topology       显示拓扑结构信息。

 2) Xiaohan Practical Camp

[root@hya ~]# lsblk
NAME            MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
sda               8:0    0   50G  0 disk 
├─sda1            8:1    0    1G  0 part /boot
└─sda2            8:2    0   49G  0 part 
  ├─centos-root 253:0    0 45.1G  0 lvm  /
  └─centos-swap 253:1    0  3.9G  0 lvm  [SWAP]
sr0              11:0    1  8.8G  0 rom  
七个栏目名称如下:
NAME :这是块设备名。
MAJ:MIN :本栏显示主要和次要设备号。
RM :本栏显示设备是否可移动设备。注意,在本例中设备sdb和sr0的RM值等于1,这说明他们是可移动设备。
SIZE :本栏列出设备的容量大小信息。例如298.1G表明该设备大小为298.1GB,而1K表明该设备大小为1KB。
RO :该项表明设备是否为只读。在本案例中,所有设备的RO值为0,表明他们不是只读的。
TYPE :本栏显示块设备是否是磁盘或磁盘上的一个分区。在本例中,sda和sdb是磁盘,而sr0是只读存储(rom)。
MOUNTPOINT :本栏指出设备挂载的挂载点。
  • The default option does not list all empty devices. To view these empty devices, use the following command:
[root@hya ~]# lsblk -a
  • The lsblk command can also be used to list the ownership of a specific device, as well as to list groups and modes. This information can be obtained by the following command:
[root@hya ~]# lsblk -m
NAME             SIZE OWNER GROUP MODE
sda               50G root  disk  brw-rw----
├─sda1             1G root  disk  brw-rw----
└─sda2            49G root  disk  brw-rw----
  ├─centos-root 45.1G root  disk  brw-rw----
  └─centos-swap  3.9G root  disk  brw-rw----
sr0              8.8G root  cdrom brw-rw----
  • This command can also only obtain the information of the specified device. This can be achieved by specifying the device name after the options provided to the lsblk command. For example, you may be interested in understanding how to display the size of your disk drive in bytes, then you can do so by running the following command:
[root@hya ~]# lsblk -b /dev/sda
NAME            MAJ:MIN RM        SIZE RO TYPE MOUNTPOINT
sda               8:0    0 53687091200  0 disk 
├─sda1            8:1    0  1073741824  0 part /boot
└─sda2            8:2    0 52612300800  0 part 
  ├─centos-root 253:0    0 48444211200  0 lvm  /
  └─centos-swap 253:1    0  4160749568  0 lvm  [SWAP]
##############或者
[root@hya ~]# lsblk --bytes /dev/sda
  • You can also combine several options to get the specified output. For example, you might want to list devices in a list format instead of the default tree format. You may also be interested in removing the titles of different column names. You can combine two different options to get the desired output, the command is as follows:
[root@hya ~]# lsblk -nl
sda           8:0    0   50G  0 disk 
sda1          8:1    0    1G  0 part /boot
sda2          8:2    0   49G  0 part 
centos-root 253:0    0 45.1G  0 lvm  /
centos-swap 253:1    0  3.9G  0 lvm  [SWAP]
sr0          11:0    1  8.8G  0 rom 
  • To get the list of SCSI devices, you can only use the -S option. This option is a capital letter S, which should not be confused with the -s option, which is used to print dependencies in reverse order.
[root@hya ~]# lsblk -S
NAME HCTL       TYPE VENDOR   MODEL             REV TRAN
sda  2:0:0:0    disk VMware,  VMware Virtual S 1.0  spi
sr0  1:0:0:0    rom  NECVMWar VMware IDE CDR10 1.00 ata
  • lsblk lists SCSI devices, and -s is the reverse order option (reverse the organization relationship between devices and partitions), which will give the following output. input the command:
[root@hya ~]# lsblk -s
NAME        MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
sda1          8:1    0    1G  0 part /boot
└─sda         8:0    0   50G  0 disk 
sr0          11:0    1  8.8G  0 rom  
centos-root 253:0    0 45.1G  0 lvm  /
└─sda2        8:2    0   49G  0 part 
  └─sda       8:0    0   50G  0 disk 
centos-swap 253:1    0  3.9G  0 lvm  [SWAP]
└─sda2        8:2    0   49G  0 part 
  └─sda       8:0    0   50G  0 disk 

 

Guess you like

Origin blog.csdn.net/yeyslspi59/article/details/108639022