Rate this page

Flattr this

Display the size of a Linux block special device

Tested on

Debian (Lenny, Squeeze)
Ubuntu (Lucid, Precise, Trusty)

Objective

To display the size of a Linux block special device

Background

A block special device typically represents a logical or physical storage device such as a hard disc drive, a disc partition or a logical volume. Unlike a regular file, the size of a block special device cannot be obtained by means such as ls -l.

Scenario

Suppose that you wish to determine the size of the block device /dev/sda.

Method

On Linux-based systems the size of a block special device can be obtained using the blockdev command provided by the util-linux package:

blockdev --getsize64 /dev/sda

This will write the size of the device in bytes to stdout.

Tags: shell