Wondering what partitions and drives are on your Ubuntu system?
lsblk command is widely used for listing mounted drives including their mount points.
No additional option and you get a list of mounted drives with partitions and mounting points.
But wait, there are more ways to list drives in Ubuntu Linux, and I will discuss them one by one.
1. Using fdisk command
The fdisk utility is mainly used to manipulate the disk partition table but when used with
-l option brings the list of partition tables for specific devices.
2. Using df command
The df (disk free) command is mainly used to display free and used disk space for each file system.
And by default, the free and used space will be shown for 1k blocks meaning you'd have to divide free/used space with 1024 to get values in Mbs.
But that can easily be overcome by using
-h option to improve readability.
3. Using parted command
As its name suggests, the parted utility is a powerful tool to manipulate your partitions but when used with
-l option to list partition layouts on all block devices.
sudo parted -l
4. Using lshw command
The lshw command is used to get detailed info related to your machine's hardware ranging from exact memory configuration, firmware version, mainboard configuration to bus speeds.
And when used with
-class disk, it will fetch detailed info about mounted drives.
sudo lshw -class disk
This utility can also give you the privilege to get output in HTML, JSON, or in XML formats.
For example, let me show you how you can get in HTML
sudo lshw -class disk -html
5. By listing contents of /dev/disk
Unless you're an advanced user, I'd not recommend this method as beginners are bound to get confused with the representation of the output.
On the other hand, it is an effective way to list disks in a more meaningful way.
ls -l /dev/disk/by-id
Similarly, you can also use the following instead of listing contents using
6. Using sfdisk command
The sfdisk is script oriented utility for manipulating disk partitions but can be used to list block devices (drives) by using
-l options and gives an identical output to
sudo fdisk -l command that I addressed earlier.
sudo sfdisk -l
This guide was a compilation of different methods through which you can easily list drives on your Ubuntu system.
I recommend using the lsblk and fdisk commands as they are more popular and straightforward. But feel free to use the ones you feel comfortable with.