You can use the command dpkg-query
to list all installed packages and their sizes on a Debian or Ubuntu system. You can then sort the list by size to find the packages that are using the most space. Here’s an example command that will list the installed packages in descending order of size:
dpkg-query -Wf '${Installed-Size}\t${Package}\n' | sort -n
This command does the following:
dpkg-query -Wf '${Installed-Size}\t${Package}\n'
lists all installed packages and their sizes in bytes, with a tab between the size and the package name.sort -n
sorts the output numerically in descending order.
This command will output a list of all the packages installed on your system and their size in bytes, ordered by size, with the largest at the top. You can then easily identify the packages that are using the most space.
You can also use the command apt list --installed
which will show the installed packages with their versions and the size.
Another option is to use the command du
which will show the disk usage of the directories and subdirectories, including files, you can use the option -h
to have the output in human-readable format.
du -h /var/cache/apt/archives
This command will show you the size of all the packages that are downloaded and kept in the cache directory of apt.
By using these commands you will be able to identify the packages that are taking the most disk space and decide whether you need them or not, you can then remove them if necessary by using the apt remove <package-name>
command.