To determine whether a drive is an SSD or an HDD on Ubuntu from the command line, you can use one of the following methods:
The lsblk command can display whether a disk is an SSD.
lsblk -d -o name,rotaname: The name of the disk.rota: Displays0for SSDs (non-rotational) and1for HDDs (rotational).
Example output:
NAME ROTA
sda 1 # HDD
sdb 0 # SSD
Replace <device> with your actual device name (e.g., sda, sdb, sdc):
cat /sys/block/sdc/queue/rotational0indicates an SSD (non-rotational).1indicates an HDD (rotational).
If the smartmontools package is installed, you can get detailed information about your drives:
sudo apt-get install smartmontools
sudo smartctl -a /dev/sdc | grep 'Rotation Rate'- If the output shows
Rotation Rate: Solid State Device, it’s an SSD. - If it shows a number (e.g.,
5400 RPMor7200 RPM), it’s an HDD.
Another way to check the device's type is by using udevadm:
udevadm info --query=property /dev/sdc | grep ID_ATA_ROTATION_RATE_RPM- If you see
ID_ATA_ROTATION_RATE_RPM=0, it's an SSD. - If it shows a number (e.g.,
5400or7200), it's an HDD.
The simplest and most direct method is to use lsblk -d -o name,rota or cat /sys/block/<device>/queue/rotational. These commands work quickly without needing additional packages and provide the information you're looking for.