How does a user list the size of each installed snap package in Ubuntu 20.04? The purpose is to get an overview perspective of the disk space utilised by each installed snap package. The command snap list
does not do this. Also, the app Disk Usage Analyzer
could not show further than /var/lib/snapd/snaps
.
All the
snap
packages are stored in/var/lib/snapd/snaps/
. This directory contains all the revisions and names of thesnap
packages. You can runls
in the directory to list all the snap packages. Using-lh
argument withls
will give you a more detailed output along with the size of the packages (and each of it's revisions). Thus, you can run the following command to list all thesnap
packages along with their installed size:Alternatively, you can use the
du
command with-hcs
argument to list the size of all the installed packages:snap list
limitationsAt a time of writing, July 2022,
snap list
command indeed doesn't support configuration for columns it would output, it's a hardcoded behavior: https://github.com/snapcore/snapd/blob/293c48dc2b97f141d1bc35d5ea91c2e3484f01fd/cmd/snap/cmd_list.goUsing snap API
Hovewer, according to the official documentation, https://snapcraft.io/docs/using-the-api, snap daemon (
snapd
) exposes its API via unix socket at/run/snapd.socket
.The
/snaps
endpoint (https://snapcraft.io/docs/snapd-api#heading--snaps) return machine-readable (JSON) information about all installed snaps.And it includes
"installed-size"
property as well.As suggested in the previously mentioned help page (https://snapcraft.io/docs/using-the-api#heading--accessing), you can get this information by issuing the following command
You can then process and analyze this data using any tool you like, would it be
jq
,python
or something else.Example of listing the size of each installed snap
Example on data from my system, with
ruby
3.0.1.Command (shell):
Output:
Overall output matches that of
snap list --all
.We can see that all these snaps are located in one (default) directory.
And running
would return a closely matching values.
Conclusion
We can see then, that approach of measuring space occupied by entries of
/var/lib/snapd/snaps
directory, suggested in an already accepted answer, wasn't wrong, as evidenced by the API data and official explanation found on https://snapcraft.io/docs/system-snap-directory.