List disks with fdisk without showing loopback disks created by snap apps

You might’ve noticed that Snap apps creates a loopback disk used for mounting the image file for the app. This clutters the UI of fdisk, df and other disk related tools.

A typical fdisk -l could show you this:

Since most regular drives starts as /dev/sd* you could simply grep the output:

sudo fdisk -l | grep "Disk /dev/sd"

Or even better, use sudo fdisk -l | grep -v "loop". The -v parameter means grep reverts the keyword so anything containing “loop” will not be shown.

Another example: df -h:

Now: df -h | grep -v loop

Note regarding grep: You only need to add quotation marks around the keyword if it’s a string which contains spaces. Single words don’t need quotes.

You can also pipe it several times through grep, like this:

sudo df -h | grep -v loop | grep -v tmp

Or take a look at this Stackoverflow thread for more grep variants