Exclude loop* snap devices from lsblk output?
Since the major node type of a loop block device is 7 (as shown in /proc/devices
), you can use the -e
or --exclude
command line switch to exclude them by major type:
-e, --exclude list Exclude the devices specified by the comma-separated list of major device numbers. Note that RAM disks (major=1) are excluded by default. The filter is applied to the top-level devices only.
Ex.
$ lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
loop1 7:1 0 17.9M 1 loop /snap/pdftk/1
loop2 7:2 0 89.3M 1 loop /snap/core/6673
loop3 7:3 0 91.1M 1 loop /snap/core/6531
loop4 7:4 0 20K 1 loop /snap/hello-world/27
loop5 7:5 0 50.7M 1 loop /snap/p7zip-desktop/163
loop6 7:6 0 20K 1 loop /snap/hello-world/29
loop7 7:7 0 17.9M 1 loop /snap/pdftk/9
loop8 7:8 0 89.4M 1 loop /snap/core/6818
sda 8:0 0 238.5G 0 disk
├─sda1 8:1 0 9.8G 0 part
├─sda2 8:2 0 164.7G 0 part
├─sda3 8:3 0 31.1G 0 part /
├─sda4 8:4 0 1K 0 part
├─sda5 8:5 0 15.3G 0 part /usr/local
└─sda6 8:6 0 17.7G 0 part /home
sr0 11:0 1 1024M 0 rom
but
$ lsblk -e7
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sda 8:0 0 238.5G 0 disk
├─sda1 8:1 0 9.8G 0 part
├─sda2 8:2 0 164.7G 0 part
├─sda3 8:3 0 31.1G 0 part /
├─sda4 8:4 0 1K 0 part
├─sda5 8:5 0 15.3G 0 part /usr/local
└─sda6 8:6 0 17.7G 0 part /home
sr0 11:0 1 1024M 0 rom
You could use grep
to filter the output:
lsblk | grep -v '^loop'
This will remove lines that start with loop
.