56

We can get CPU information using lscpu command, is there any command to get hard disk information on Linux terminal, in a similar way?

Anthon
  • 79,293
Varun
  • 571

4 Answers4

78

If you are looking for partitioning information you can use fdisk or parted.

If you are more interested into how the various partitions are associated with the mount points try lsblk which I often use as:

lsblk -o "NAME,MAJ:MIN,RM,SIZE,RO,FSTYPE,MOUNTPOINT,UUID"

to include UUID info.

And finally smartctl -a /dev/yourdrive gives you detailed info like:

=== START OF INFORMATION SECTION ===
Device Model:     WDC WD40EFRX-68WT0N0
Serial Number:    WD-WCC4E4LA4965
LU WWN Device Id: 5 0014ee 261ca5a3f
Firmware Version: 82.00A82
User Capacity:    4,000,787,030,016 bytes [4.00 TB]
Sector Sizes:     512 bytes logical, 4096 bytes physical
Rotation Rate:    5400 rpm
Device is:        Not in smartctl database [for details use: -P showall]
ATA Version is:   ACS-2 (minor revision not indicated)
SATA Version is:  SATA 3.0, 6.0 Gb/s (current: 6.0 Gb/s)
Local Time is:    Sun Apr  3 10:59:55 2016 CEST
SMART support is: Available - device has SMART capability.
SMART support is: Enabled

and more.

Some of these commands need to be run sudo to get all info.

Anthon
  • 79,293
32

You can use lshw:

sudo lshw -c disk

But for newer kernels, i would suggest the portable and stable way of reading from sysfs:

/sys/block/sd*/device/*
heemayl
  • 56,300
  • Using sysfs is portable and stable?? – Otheus Apr 03 '16 at 08:57
  • @Otheus unless you are using archaic kernel.. – heemayl Apr 03 '16 at 08:58
  • I'm asking because I have no idea. There seems to be no requirement that /sys is actually mounted, and I don't recall seeing it on certain embedded flavors. I also have no idea if it is declared "stable" by the linux kernel maintainers or if, as has been in the past, its interface might change from version to version.

    BTW: You might want to note /sys/block/sd* will pick up only scsi disks. You'd have to do something more clever to figure out what block devices are actually disks, and some way to distinguish virtual from physical, eliminate loop, ram, and device mapper devices

    – Otheus Apr 03 '16 at 09:27
22

Another one you can try in addition to what has already been suggested is:

hdparm -I /dev/sda

From the manpage:

DESCRIPTION

   hdparm provides a command line interface to various kernel interfaces
   supported by the Linux SATA/PATA/SAS "libata" subsystem and the older
   IDE driver subsystem.  Many newer (2008 and later) USB drive
   enclosures now also support "SAT" (SCSI-ATA Command Translation) and
   therefore may also work with hdparm.  E.g. recent WD "Passport"
   models and recent NexStar-3 enclosures.  Some options may work
   correctly only with the latest kernels.
muru
  • 72,889
  • By this command you can get disk's serial number even if it is connected via adapter to USB. – pbies Dec 25 '19 at 00:52
9

You can use the following command:

lshw -class disk -class storage
GAD3R
  • 66,769