Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get hard drive model name with bash

Tags:

bash

terminal

I want to get the various model names of my hard drives using bash.

I can do it if there's just one, using hwinfo like this:

hwinfo --ide|grep Model|sed -ne '/Model/s/.*Model: "\([^"]*\)".*/\1/p'

But this obviously fails when there's more than one. One regular hwinfo output when there are several hard drives is this:

[faidoc@Delorean ~]$ hwinfo --ide
11: IDE 200.0: 10600 Disk                                       
  [Created at block.245]
  Unique ID: 3OOL.XFCtBh10jZ2
  Parent ID: qnJ_.3_X41NtKT36
  SysFS ID: /class/block/sda
  SysFS BusID: 2:0:0:0
  SysFS Device Link: /devices/pci0000:00/0000:00:0d.0/ata3/host2/target2:0:0/2:0:0:0
  Hardware Class: disk
  Model: "VBOX HARDDISK"
  Vendor: "VBOX"
  Device: "HARDDISK"
  Revision: "1.0"
  Serial ID: "VBfa9b1456-03d78f51"
  Driver: "ahci", "sd"
  Driver Modules: "ahci"
  Device File: /dev/sda
  Device Files: /dev/sda, /dev/disk/by-id/ata-VBOX_HARDDISK_VBfa9b1456-03d78f51
  Device Number: block 8:0-8:15
  BIOS id: 0x80
  Geometry (Logical): CHS 1305/255/63
  Size: 20971520 sectors a 512 bytes
  Capacity: 10 GB (10737418240 bytes)
  Config Status: cfg=new, avail=yes, need=no, active=unknown
  Attached to: #10 (SATA controller)

12: IDE 300.0: 10600 Disk
  [Created at block.245]
  Unique ID: WZeP.0xN7VsONW+D
  Parent ID: qnJ_.3_X41NtKT36
  SysFS ID: /class/block/sdb
  SysFS BusID: 3:0:0:0
  SysFS Device Link: /devices/pci0000:00/0000:00:0d.0/ata4/host3/target3:0:0/3:0:0:0
  Hardware Class: disk
  Model: "VBOX HARDDISK"
  Vendor: "VBOX"
  Device: "HARDDISK"
  Revision: "1.0"
  Serial ID: "VB350f9911-48221ae2"
  Driver: "ahci", "sd"
  Driver Modules: "ahci"
  Device File: /dev/sdb
  Device Files: /dev/sdb, /dev/disk/by-id/ata-VBOX_HARDDISK_VB350f9911-48221ae2
  Device Number: block 8:16-8:31
  BIOS id: 0x81
  Geometry (Logical): CHS 2349/255/63
  Size: 37748736 sectors a 512 bytes
  Capacity: 18 GB (19327352832 bytes)
  Config Status: cfg=new, avail=yes, need=no, active=unknown
  Attached to: #10 (SATA controller)

Every drive begans with for example "11:" or "12:" so if I could get one at a time that will be the solution.

Any ideas?

Thanks

like image 564
codiaf Avatar asked Mar 03 '26 17:03

codiaf


1 Answers

You can get the info with:

hdparm -i /dev/sda | grep -i model

or, if you want just the model name:

hdparm -i /dev/sda | perl -n -e 'print "$1\n" if (m/model=(.+?),/i);'
like image 122
Olaf Dietsche Avatar answered Mar 05 '26 08:03

Olaf Dietsche