blkid Command Examples in Linux
Last Updated :
13 Dec, 2023
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:
|
-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.
list of all block devices with their typesDisplay 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.)
attributes of a single block deviceFormatting 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
list of block devices namesPrint all devices with their attributes in a tabular format.
blkid -o 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
list of all file_system typesSearch 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
list of block devices of type ext4Print the list of block devices having LABEL value as SYSTEM
blkid -t LABEL=SYSTEM
list of block devices having label SYSTEMPrint block device having UUID value BADE8EBBDE8E6F85. Since UUID is unique only one block device will be listed in the output.
blkid -t UUID=BADE8EBBDE8E6F85
block device with UUID value BADE8EBBDE8E6F85Conclusion
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.
Similar Reads
bg command in Linux with Examples
In Linux, the bg command is a useful tool that allows you to manage and move processes between the foreground and background. It's especially helpful when you want to multitask in the terminal by placing a process in the background, enabling you to continue using the terminal for other commands whil
3 min read
bc command in Linux with examples
bc command is used for command line calculator. It is similar to basic calculator by using which we can do basic mathematical calculations. Arithmetic operations are the most basic in any kind of programming language. Linux or Unix operating system provides the bc command and expr command for doing
11 min read
bzip2 command in Linux with Examples
bzip2 command in Linux is used to compress and decompress the files i.e. it helps in binding the files into a single file which takes less storage space than the original file used to take. It has a slower decompression time and higher memory use. It uses Burrows-Wheeler block sorting text compressi
3 min read
builtin command in Linux with examples
The builtin command in shell scripting is used to execute a shell builtin, passing it arguments, and also retrieving its exit status. Its primary use is to ensure that you can call the original functionality of a builtin command even when a function with the same name is defined. Syntaxbuiltin [shel
2 min read
ACPI command in Linux with examples
ACPI is the command in Linux that helps the users in managing power settings. It also helps in monitoring the hardware status efficiently. It facilitates with providing essential information such as battery health, CPU temperatures, and fan speeds, providing support in system maintenance and perform
4 min read
bzdiff command in linux with examples
bzdiff command in Linux is used to compare the bzip2 compressed files. Bzcmp and bzdiff are used to invoke the cmp or the diff program on bzip2 compressed files. All options specified are passed directly to cmp or diff. If only one file is specified, then the files compared are file1 and an uncompre
1 min read
badblocks command in Linux with examples
badblock command in Linux is used to search for bad blocks (block of memory which has been corrupted and can no longer be used reliably) in a device. It is by default set to run in non-destructive read-only mode. Syntax: badblocks [-b block_size] [-i input_file] [-o output_file] [-svwnf] [-c blocks_
2 min read
as command in linux with examples
as command is the portable GNU assembler in Linux. Using as command, we can read and assemble a source file. The main purpose of 'as' is to assemble the output of the GNU compiler of the C language.as command reads and assembles the .s File. Also, whenever you do not specify the file, it normally re
3 min read
aptitude command in Linux with examples
The aptitude command in Linux provides a user-friendly interface to interact with the machine's package manager. It functions similarly to a control panel, like in Windows, allowing you to install, upgrade, and remove packages. The command can be used in either a visual interface or directly via the
4 min read
addr2line command in Linux with Examples
'addr2line' command in Linux is used to convert addresses into file names and line numbers. When the executable files/object files are run with the 'objdump' command, the file is de-assembled and the machine code is displayed. These machine instructions for the executable are displayed along with th
4 min read