How to List Disks in Linux Command Line

Written by: Linuxopsys   |   Last updated: June 21, 2022

Linux system administrators generally list disks to check the whole disk space. Listing disks also helps see the attached disks to the system, partitions, and disk filesystem.

In a Linux system, there are several ways to list all the hard drives. In this tutorial, we learn how to list disks in Linux using the command line.

1. lsblk

lsblk (list block devices) is used to list information of all available block devices, such as hard disk, and flash drives.

Just typing the command lsblk will list all block devices in form of a tree format. This is a handy and simple way to list disks.

lsblk

Output:

sda      8:0    0 238.5G  0 disk 
 ├─sda1   8:1    0   529M  0 part 
 ├─sda2   8:2    0   100M  0 part /boot/efi
 ├─sda3   8:3    0    16M  0 part 
 ├─sda4   8:4    0 165.8G  0 part 
 ├─sda5   8:5    0    70G  0 part /
 └─sda6   8:6    0     2G  0 part [SWAP]
 zram0  252:0    0     8G  0 disk [SWAP]

2. df -h

The df command is used to list the amount of disk space available as a whole. Default df command prints device name, total blocks, used disk space, available disk space, percentage of used space, filesystem mount point, and also prints the remote-mounted filesystems such as NFS.

The command df -h list available space of all disks in a human-readable form.

sudo df -h

Output:

Filesystem      Size  Used Avail Use% Mounted on
 devtmpfs        5.8G     0  5.8G   0% /dev
 tmpfs           5.8G   90M  5.7G   2% /dev/shm
 tmpfs           2.4G   11M  2.4G   1% /run
 tmpfs           4.0M     0  4.0M   0% /sys/fs/cgroup
 /dev/sda5        69G   62G  3.1G  96% /
 tmpfs           5.8G  4.7M  5.8G   1% /tmp
/dev/sda2        96M   41M   56M  43% /boot/efi
 tmpfs           1.2G  200K  1.2G   1% /run/user/1000

An alternative command for df -h is findmnt --df which gives a similar output.

3. fdisk -l

The fdisk command is a text-based utility used to manage disk partitions. Using fdisk you can list disk partitions, create a new partition, delete an existing hard disk partition and view the size of the partition.

Use fdisk -l to view all available disk partitions

sudo fdisk -l

Output:


Disk /dev/sda: 238.47 GiB, 256060514304 bytes, 500118192 sectors
 Disk model: SK hynix SC300B 
 Units: sectors of 1 * 512 = 512 bytes
 Sector size (logical/physical): 512 bytes / 4096 bytes
 I/O size (minimum/optimal): 4096 bytes / 4096 bytes
 Disklabel type: gpt
 Disk identifier: FF57C955-D98A-49C4-B1ED-835A44F2A0A4
 Device         Start       End   Sectors   Size Type
 /dev/sda1       2048   1085439   1083392   529M Windows recovery environment
 /dev/sda2    1085440   1290239    204800   100M EFI System
 /dev/sda3    1290240   1323007     32768    16M Microsoft reserved
 /dev/sda4    1323008 349122559 347799552 165.8G Microsoft basic data
 /dev/sda5  349122560 495923199 146800640    70G Linux filesystem
 /dev/sda6  495923200 500117503   4194304     2G Linux swap
 Disk /dev/zram0: 8 GiB, 8589934592 bytes, 2097152 sectors
 Units: sectors of 1 * 4096 = 4096 bytes
 Sector size (logical/physical): 4096 bytes / 4096 bytes
 I/O size (minimum/optimal): 4096 bytes / 4096 bytes
Disk /dev/loop0: 207.15 MiB, 217214976 bytes, 424248 sectors
 Units: sectors of 1 * 512 = 512 bytes
 Sector size (logical/physical): 512 bytes / 512 bytes
 I/O size (minimum/optimal): 512 bytes / 512 bytes
 Disk /dev/loop1: 99.18 MiB, 103993344 bytes, 203112 sectors
 Units: sectors of 1 * 512 = 512 bytes
 Sector size (logical/physical): 512 bytes / 512 bytes
 I/O size (minimum/optimal): 512 bytes / 512 bytes

4. parted -l

Parted is a useful and powerful tool used to manage hard disk partitions from the command line like list, create, shrink, delete, find and rescue disk partitions. With the parted command you can easily manage all hard disk partitions.

parted -l command will lists disks partition layout on all block devices.

sudo parted -l

Output:

Model: ATA SK hynix SC300B (scsi)
 Disk /dev/sda: 256GB
 Sector size (logical/physical): 512B/4096B
 Partition Table: gpt
 Disk Flags: 
 Number  Start   End    Size    File system     Name                          Flags
  1      1049kB  556MB  555MB   ntfs            Basic data partition          hidden, diag
  2      556MB   661MB  105MB   fat32           EFI System Partition          boot, esp
  3      661MB   677MB  16.8MB                  Microsoft reserved partition  msftres
  4      677MB   179GB  178GB   ntfs            Basic data partition          msftdata
  5      179GB   254GB  75.2GB  ext4
  6      254GB   256GB  2147MB  linux-swap(v1)                                swap
 Model: Unknown (unknown)
 Disk /dev/zram0: 8590MB
 Sector size (logical/physical): 4096B/4096B
 Partition Table: loop
 Disk Flags: 
 Number  Start  End     Size    File system     Flags
  1      0.00B  8590MB  8590MB  linux-swap(v1)

5. cfdisk

The cfdisk is slightly different from the above commands, it provides the graphics view in a text-based terminal interface to manage disks. Using cfdisk you can list, create, delete and modify partitions on a disk device.

sudo cfdisk

Output:

                                            Disk: /dev/sda                        Size: 238.47 GiB, 256060514304 bytes, 500118192 sectors                      Label: gpt, identifier: FF57C955-D98A-49C4-B1ED-835A44F2A0A4 Device                   Start            End        Sectors        Size Type
        /dev/sda1                 2048        1085439        1083392        529M Windows recovery environment     
         /dev/sda2              1085440        1290239         204800        100M EFI System
         /dev/sda3              1290240        1323007          32768         16M Microsoft reserved
         /dev/sda4              1323008    349122559      347799552      165.8G Microsoft basic data
         /dev/sda5            349122560    495923199      146800640         70G Linux filesystem
         /dev/sda6            495923200    500117503        4194304          2G Linux swap    
 ┌──────────────────────────────────────────────────────────────────────────────────────────────────────────┐
  │  Partition name: Basic data partition                                                                    │
  │  Partition UUID: E73F9719-F144-42A8-87BC-862FB470828B                                                    │
  │  Partition type: Windows recovery environment (DE94BBA4-06D1-4D40-A16A-BFD50179D6AC)                     │
  │    Attributes: RequiredPartition                                                                       │
  │ Filesystem UUID: 8C0A62C30A62A9C2                                                                        │
  │Filesystem LABEL: Recovery                                                                                │
  │    Filesystem: ntfs                                                                                    │
  └──────────────────────────────────────────────────────────────────────────────────────────────────────────┘
               [ Delete ]  [ Resize ]  [  Quit  ]  [  Type  ]  [  Help  ]  [  Write ]  [  Dump  ]

Example:

cfdisk

6. sfdisk -l

The sfdisk is a partitions table editor. It can list the partitions on a device, list the size of a partition, check the partitions on a device, and preparation a device. It is not designed for large partitions.

sfdisk -l will list partitions of disk.

sudo sfdisk -l

Output:

Disk /dev/sda: 238.47 GiB, 256060514304 bytes, 500118192 sectors
 Disk model: SK hynix SC300B 
 Units: sectors of 1 * 512 = 512 bytes
 Sector size (logical/physical): 512 bytes / 4096 bytes
 I/O size (minimum/optimal): 4096 bytes / 4096 bytes
 Disklabel type: gpt
 Disk identifier: FF57C955-D98A-49C4-B1ED-835A44F2A0A4
 Device         Start       End   Sectors   Size Type
 /dev/sda1       2048   1085439   1083392   529M Windows recovery environment
 /dev/sda2    1085440   1290239    204800   100M EFI System
 /dev/sda3    1290240   1323007     32768    16M Microsoft reserved
 /dev/sda4    1323008 349122559 347799552 165.8G Microsoft basic data
 /dev/sda5  349122560 495923199 146800640    70G Linux filesystem
 /dev/sda6  495923200 500117503   4194304     2G Linux swap
 Disk /dev/zram0: 8 GiB, 8589934592 bytes, 2097152 sectors
 Units: sectors of 1 * 4096 = 4096 bytes
 Sector size (logical/physical): 4096 bytes / 4096 bytes
 I/O size (minimum/optimal): 4096 bytes / 4096 bytes
 Disk /dev/loop0: 207.15 MiB, 217214976 bytes, 424248 sectors
 Units: sectors of 1 * 512 = 512 bytes
 Sector size (logical/physical): 512 bytes / 512 bytes
 I/O size (minimum/optimal): 512 bytes / 512 bytes
 Disk /dev/loop1: 99.18 MiB, 103993344 bytes, 203112 sectors
 Units: sectors of 1 * 512 = 512 bytes
 Sector size (logical/physical): 512 bytes / 512 bytes
 I/O size (minimum/optimal): 512 bytes / 512 bytes

7. ls -l /dev/disk/by-id

ls command is a very simple but powerful command used for listing files and directories. We can list disks by listing the directory /dev/disk/by-id.

ls -l /dev/disk/by-id

Output:

 total 0
 lrwxrwxrwx 1 root root  9 Jun 20 23:26 ata-SK_hynix_SC300B_HFS256G39MND-3510B_FI68N023911308NC9 -> ../../sda
 lrwxrwxrwx 1 root root 10 Jun 20 23:26 ata-SK_hynix_SC300B_HFS256G39MND-3510B_FI68N023911308NC9-part1 -> ../../sda1
 lrwxrwxrwx 1 root root 10 Jun 20 23:26 ata-SK_hynix_SC300B_HFS256G39MND-3510B_FI68N023911308NC9-part2 -> ../../sda2
 lrwxrwxrwx 1 root root 10 Jun 20 23:26 ata-SK_hynix_SC300B_HFS256G39MND-3510B_FI68N023911308NC9-part3 -> ../../sda3
 lrwxrwxrwx 1 root root 10 Jun 20 23:26 ata-SK_hynix_SC300B_HFS256G39MND-3510B_FI68N023911308NC9-part4 -> ../../sda4
 lrwxrwxrwx 1 root root 10 Jun 20 23:26 ata-SK_hynix_SC300B_HFS256G39MND-3510B_FI68N023911308NC9-part5 -> ../../sda5
 lrwxrwxrwx 1 root root 10 Jun 20 23:26 ata-SK_hynix_SC300B_HFS256G39MND-3510B_FI68N023911308NC9-part6 -> ../../sda6
 lrwxrwxrwx 1 root root  9 Jun 20 23:26 wwn-0x5ace42e0900dd482 -> ../../sda
 lrwxrwxrwx 1 root root 10 Jun 20 23:26 wwn-0x5ace42e0900dd482-part1 -> ../../sda1
 lrwxrwxrwx 1 root root 10 Jun 20 23:26 wwn-0x5ace42e0900dd482-part2 -> ../../sda2
 lrwxrwxrwx 1 root root 10 Jun 20 23:26 wwn-0x5ace42e0900dd482-part3 -> ../../sda3
 lrwxrwxrwx 1 root root 10 Jun 20 23:26 wwn-0x5ace42e0900dd482-part4 -> ../../sda4
 lrwxrwxrwx 1 root root 10 Jun 20 23:26 wwn-0x5ace42e0900dd482-part5 -> ../../sda5
 lrwxrwxrwx 1 root root 10 Jun 20 23:26 wwn-0x5ace42e0900dd482-part6 -> ../../sda6

You can also list by:

  • by-label
  • by-partlabel
  • by-partuuid
  • by-path
  • by-uuid

8. lshw -class disk

lshw is a Linux tool that is used to generate detailed information on the system's hardware configuration.

Use -class disk to list disk information.

sudo lshw -class disk

Output:

   *-disk                    
        description: ATA Disk
        product: SK hynix SC300B
        physical id: 0.0.0
        bus info: scsi@1:0.0.0
        logical name: /dev/sda
        version: 0P00
        serial: FI68N023911308NC9
        size: 238GiB (256GB)
        capabilities: gpt-1.00 partitioned partitioned:gpt
        configuration: ansiversion=5 guid=ff57c955-d98a-49c4-b1ed-835a44f2a0a4 logicalsectorsize=512 sectorsize=4096

Also, it is possible to output -class disk as -json or -html or -xml.

sudo lshw -class disk -json

Output:

 {
     "id" : "disk",
     "class" : "disk",
     "claimed" : true,
     "handle" : "GUID:ff57c955-d98a-49c4-b1ed-835a44f2a0a4",
     "description" : "ATA Disk",
     "product" : "SK hynix SC300B",
     "physid" : "0.0.0",
     "businfo" : "scsi@1:0.0.0",
     "logicalname" : "/dev/sda",
     "dev" : "8:0",
     "version" : "0P00",
     "serial" : "FI68N023911308NC9",
     "units" : "bytes",
     "size" : 256060514304,
     "configuration" : {
       "ansiversion" : "5",
       "guid" : "ff57c955-d98a-49c4-b1ed-835a44f2a0a4",
       "logicalsectorsize" : "512",
       "sectorsize" : "4096"
     },
     "capabilities" : {
       "gpt-1.00" : "GUID Partition Table version 1.00",
       "partitioned" : "Partitioned disk",
       "partitioned:gpt" : "GUID partition table"
     },
     "children" : [
 ]
 }

Conclusion

For all commands, except lsblk and ls -l dev/disk, need root access or superuser permissions to run it.

In this tutorial, we learned how to list disks in Linux using the command line.

SHARE

Comments

Please add comments below to provide the author your ideas, appreciation and feedback.

Leave a Reply

Leave a Comment