Removing Loop Devices from fdisk Output

Posted by JD 03/04/2020 at 17:00

Since Canonical decided to start pushing snap packages, many old Unix commands have had their output screwed up by snap loop device output. That output is meaningless almost always, so we usually don’t want/need to see it.

Below are my attempts to remove the snap crap output from commonly used commands. I’ve been shamelessly stealing some of these command options from people around the internet. Most end up as aliases for my shell. Hopefully, they will be useful to someone else.

Thanks to the people who posted these elsewhere. Not all of them work in all environments or even on all my own systems. YMMV.

df output:
alias dft='df -hT -x squashfs -x tmpfs -x devtmpfs'
I don’t want to see pseudo-file systems. Only works for mounted storage.

lsblk output:
alias lsblkt='lsblk -e 7 -o name,size,type,fstype,mountpoint'
Blocks loop devices but still shows some useful information for all connected storage.

fdiisk output:
sudo fdisk -l | perl -lne 'print if /^Disk \/dev\/[fhnsv]/ ... /\n\n/'
this one actually needs to be killed on one of my systems, but works fine on all the others. I tried not to include any LVM2 LVs, but that has failed. If using LVM2, best to stay with the full output and use pvs, vgs, lvs commands to see more details.
It should get floppy disks, IDE HDDs, SATA HDDs/SSDs, NVMe SSDs, and virtual machine storage devices. In theory. Please manually verify that it works for your storage before trusting it.

Have improvements or fixes? Please comment. I’m fairly certain they can be improved.

If you like this, check out my Quick System Overview Recently updated. But inxi is still pretty awesome.