0

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
  • 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 2 '18 at 14:16
4

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.

|improve this answer|||||
  • 3
    lsblk -I 8 -d works too. – NickD Jan 2 '18 at 14:15
  • 1
    @Nick: if -I 8 is supported. Looks like for GNU systems, it was introduced somewhere between coreutils 8.21 and 8.25. – user4556274 Jan 2 '18 at 14:19
0

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.

|improve this answer|||||
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
|improve this answer|||||

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.