5

I want to capture only the disks from lsblk

as showing here fd0 also appears in spite its not really disk for use

in this case we can just do lsblk | grep disk | grep -v fd0

but maybe we missed some other devices that need to filter them by grep -v

what other disk devices that could be appears from lsblk | grep disk and not really disks ?

lsblk | grep disk 

fd0                2:0    1     4K  0 disk
sda                8:0    0   100G  0 disk
sdb                8:16   0     2G  0 disk /Kol
sdc                8:32   0     2G  0 disk
sdd                8:48   0     2G  0 disk
sde                8:64   0     2G  0 disk
sdf                8:80   0     2G  0 disk


lsblk
NAME             MAJ:MIN RM   SIZE RO TYPE MOUNTPOINT
fd0                2:0    1     4K  0 disk
sda                8:0    0   150G  0 disk
├─sda1             8:1    0   500M  0 part /boot
└─sda2             8:2    0 149.5G  0 part
├─vg00-yv_root 253:0    0  19.6G  0 lvm  /
├─vg00-yv_swap 253:1    0  15.6G  0 lvm  [SWAP]
└─vg00-yv_var  253:2    0   100G  0 lvm  /var
sdb                8:16   0     2G  0 disk /Kol
sdc                8:32   0     2G  0 disk
sdd                8:48   0     2G  0 disk
sde                8:64   0     2G  0 disk
sdf                8:80   0     2G  0 disk
sr0               11:0    1  1024M  0 rom
yael
  • 12,598
  • 51
  • 169
  • 303
  • 2
    fd0 is a floppy disk, so it *is* a "disk". There may be nothing in it, but the device exists. Ditto for sr0. There may be SCSI or SATA disks that are not mounted/ Are they to be included or not? IOW, the selection criteria have to be specified a bit more precisely. – NickD Jan 02 '18 at 14:16

4 Answers4

12

If you want only disks identified as SCSI by the device major number 8, without device partitions, you could search on device major rather than the string "disk":

lsblk -d | awk '/ 8:/'

where the -d (or --no-deps) option indicates to not include device partitions.

For reasonably recent linux systems, the simpler

lsblk -I 8 -d

should suffice, as noted by user Nick.

user4556274
  • 8,725
  • 2
  • 31
  • 37
3

I wanted to get only the device names of all disks without any other output. Ended up using this:

lsblk -nd --output NAME

Which yields something like

sda
sdb

-d only outputs disks, -n removes the header line, and --output NAME make sure only the name of the device is listed.

thrau
  • 131
  • 3
2

I don't have enough reputation to comment, so here's my comment as an answer.

sudo lsblk -I 8,259 -d  

if you want to include nvme devices in the list.

don_crissti
  • 79,330
  • 30
  • 216
  • 245
silverduck
  • 121
  • 2
0

Also you can show the internal kernel device name with:

lsblk -np --output KNAME
/dev/nvme0n1
/dev/nvme1n1
/dev/nvme0n1p1
/dev/nvme1n1p1
/dev/nvme0n1p2
/dev/nvme1n1p2
panticz
  • 151
  • 2