Open In App

blkid Command Examples in Linux

Last Updated : 13 Dec, 2023
Improve
Improve
Like Article
Like
Save
Share
Report

blkid is a command to locate or print block device attributes. A block device can be a hard drive, solid-state drive (SSD), or removable storage device, such as a USB drive. It can determine the type of content (e.g., filesystem or swap) that a block device holds, and also the attributes (tokens, NAME=value pairs) from the content metadata (e.g., LABEL or UUID fields). The blkid command is part of the util-linux package. You need a Linux terminal to use this command.

Syntax of `blkid` Command in Linux

blkid [OPTIONS] [DEVICE_NAME]

Here,

OPTIONS – various command options to modify the behaviour of the blkid command.

DEVICE NAME – name of the device to be searched. This can be omitted.

Options available in `blkid` Command in Linux

Here is a list of some common options for the blkid command:

option

long option

description

-d

–no-encoding

Don’t encode non-printing characters.

-g

–garbage-collect

Remove devices that no longer exist.

-h

–help

Display a usage message and exit.

-k

–list-filesystems

List all known filesystems and RAIDs and exit.

-o

–output FORMAT

Use the specified output format. FORMAT can be:

  • full – print all tags
  • value – print value of the tags
  • list – print devices in a user-friendly format
  • device – print device name only

and so on.

-t

–match-token NAME=VALUE

Search for block devices having attributes named NAME and value as VALUE. NAME can be TYPE, LABEL or UUID.

-U

–uuid [UUID]

Look up the device that uses this filesystem UUID.

For more options and details for the command check out the manual for the blkid command:

man blkid

Examples of blkid command in Linux

blkid has two main forms of operation: either searching for a device with a specific NAME=value pair, or displaying NAME=value pairs for one or more specified devices.

Display information of all block devices on your system using blkid command.

To display a list of all the block devices in your system enter the following command in the terminal.

blkid

If all block devices are not listed try re-executing the command in sudo mode.

sudo blkid

You will see a list of names of all block devices along with their information printed in the terminal.

blkid

list of all block devices with their types

Display information of a single block device using blkid command.

To display information about a single block device add its name after the command.

blkid /dev/nvme0n1p1

This commands prints the attributes of the block device mentioned. (Note: The name of the block device you entered should be present on your system.)

blkid_block_device_

attributes of a single block device

Formatting command output using blkid command.

blkid command comes with multiple options to alter the behaviour of the command ouput. You can use the -o option along with some predefined value to modify the output of the command.

Print list of all block device names on your system

blkid -o device
block_device_names

list of block devices names

Print all devices with their attributes in a tabular format.

blkid -o list

blkid_list

Print a list of file available file system type using blkid command.

Enter the following command to print all the available filesystem types on your system.

blkid -k
file-system-types

list of all file_system types

Search devices with matching attribute names using blkid command.

You can also search for block device by matching attributes such as TYPE, LABEL or UUID using the -t (–match-token) option.

Find all block devices of TYPE ext4 using the following command:

blkid -t TYPE=ext4
blkid_type_search

list of block devices of type ext4

Print the list of block devices having LABEL value as SYSTEM

blkid -t LABEL=SYSTEM
blkid_label_search

list of block devices having label SYSTEM

Print block device having UUID value BADE8EBBDE8E6F85. Since UUID is unique only one block device will be listed in the output.

blkid -t UUID=BADE8EBBDE8E6F85
blkid_uuid_search

block device with UUID value BADE8EBBDE8E6F85

Conclusion

In this article we discussed the blkid command in Linux which is a crucial tool for identifying and displaying attributes of block devices, including hard drives and USBs. With options like listing filesystems, formatting output, and searching devices based on attributes, blkid provides a versatile solution for users managing storage devices from the Linux terminal. Its flexibility and functionality make it an essential resource for efficiently obtaining information about block devices on a system.



Like Article
Suggest improvement
Share your thoughts in the comments

Similar Reads