Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to use lsblk and blkid to display device information in Linux system

2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/01 Report--

This article mainly explains "how to use lsblk and blkid to display device information in the Linux system". The content in the article is simple and clear, and it is easy to learn and understand. Please follow the editor's train of thought to study and learn "how to use lsblk and blkid to display device information in the Linux system".

Today we will show you how to use lsblk and blkid tools to find information about block devices. We are using a machine with CentOS 7.0 installed.

Lsblk

Lsblk is a Linux tool that displays information about all available block devices in your system. It gets information from the sysfs file system. By default, this tool will display all block devices in a tree format (except for memory virtual disks).

Lsblk default output

By default, lsblk outputs block devices in a tree format:

NAME-name of the device

MAJ:MIN-each device in the Linux operating system is represented by a file, and for block (disk) devices, the primary and secondary device numbers are used to describe the device.

RM-removable device. If this is a removable device, 1 will be displayed, otherwise 0 will be displayed.

TYPE-Type of device

MOUNTPOINT-the location where the device is mounted

RO-for read-only file systems, 1 is shown here, otherwise 0 is displayed.

SIZE-the capacity of the device

Show the owner of the device

To display information about the device owner, including the user, group, and file system mount mode of the file, you can use the-m option, like this:

The code is as follows:

Lsblk-m

List device blocks

If you only want to list devices and don't want them to output in a tree, you can use the-l option:

The code is as follows:

Lsblk-l

Use in script

Advanced technique: if you want to use it in a script and want to remove the header, you can use the-n option:

The code is as follows:

Lsblk-ln

The code is as follows:

Blkid

The blkid command is a command-line tool that displays information about available block devices. It can identify the type of content of a block device (such as file system, exchange) and obtain attributes (such as tokens and key-value pairs) from the metadata of the content (such as volume labels or UUID fields). It has two main functions: searching for a device with a specified key-value pair, or displaying key-value pairs for one or more devices.

How to use blkid

Running blkid directly without adding any parameters will output all available devices, their universal unique identification number (UUID), file system type, and volume label (if set).

The code is as follows:

# blkid

List devices by name or UUID

If you only want to display information about a specific device, you can add the name of that device to the blkid as an option:

The code is as follows:

# blkid / dev/sda1

If you know the UUID of a device and want to know its device name, you can use the-U option, like this:

The code is as follows:

# blkid-U d3b1dcc2-e3b0-45b0-b703-d6d0d360e524

detailed information

If you want more details, you can use the-p and-o udev options to display them in a neat format, like this:

The code is as follows:

# blkid-po udev / dev/sda1

Reset the cache

Sometimes the list of devices may not be updated, in which case you can use the-g option to clean up the blkid cache to remove devices that no longer exist.

The code is as follows:

# blkid-g

Thank you for your reading, the above is the content of "how to use lsblk and blkid to display equipment information in the Linux system". After the study of this article, I believe you have a deeper understanding of how to use lsblk and blkid to display equipment information in the Linux system. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report