Skip to content

[Linux] How to Hide the /dev/loop* device displayed by the df command

If you are familiar with the use of Linux system, you must be familiar with df command. df is a command commonly used to check the allocation of system hard disks.

But in Ubuntu 18.04 (or other versions), if you use df command, you will see a lot of /dev/loop* devices.

this makes it difficult for us to see the space used by the hard disk at a glance.

df -h

Output:

Just like this.

So today I will record how to hide these /dev/loop* devices.


/dev/loop*

First of all, I want to clarify that /dev/loop* is not a stupid design (some friends around me dislike it like this, but I think my friends just think it makes the interface unsightly XD).

On the contrary, /dev/loop* is a very useful design. The reason is that it treats specific "files", "image files", etc. as an accessible device, which is mounted like a hardware device.

So, let’s take a look at how to hide this information so that it does not appear in the result of the df command.


Hide the df command results

To hide df and display the results, in fact, it is not difficult to put it bluntly. In df, there is a hidden option of df -x.

For example, if I want to hide the squashfs devices in /dev/loop*, then I use the following command:

df -h -x squashfs

Output:

As you can see, the items displayed by df have been cleaned a lot

Next, we can continue to hide the tmpfs and udev projects. It should be noted that each hidden item must be preceded by the -x parameter.

df -h -x squashfs -x tmpfs -x devtmpfs

Output:

Best, the df command we can see is only the system disk and D slot mounted on my computer.


Set shortcut commands (optional)

Write in ~/.bashrc:

alias mydf='df -h -x squashfs -x tmpfs -x devtmpfs'

After the archive is gone, use the following command to make the settings take effect:

source ~/.bashrc

In this way, you can directly enter mydf in the future to see the clean device information.


References

Tags:

Leave a Reply