我想使用 bash 获取硬盘驱动器的各种型号名称。
如果只有一个,我可以这样做,使用这样的 hwinfo:
hwinfo --ide|grep Model|sed -ne '/Model/s/.*Model: "\([^"]*\)".*/\1/p'
但是,当有多个时,这显然会失败。当有多个硬盘驱动器时,一个常规的 hwinfo 输出是这样的:
[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)
每个驱动器都以例如“11:”或“12:”开头,所以如果我能一次得到一个,那将是解决方案。
有任何想法吗?
谢谢