3

I would like to remove unneeded packages. I have already removed large files (using k4dirstat) and the only left bit is a few hundreds of packages I installed but I do not use most of them (the install, without /home, takes 15GB).

It is possible to remove a package with dependencies individually using 'apt-get purge', and to see space that would be freed. However, this way to see space a package occupies is slow and manual, which is a problem.

How do I display packages with the disk space purging them would free under Debian?

3
  • Why not use dpkg-query ? See also this link.
    – harrymc
    Commented Jan 2, 2014 at 10:18
  • Please post this as an answer. It appears to adequately address the problem stated in the question.
    – user89272
    Commented Jan 3, 2014 at 4:21
  • It doesn't look like any of those options give you the "remove dependencies" total sizes. e.g. The check shows: 108765 wine1.4-amd64 But when you go to remove it... root@ciro:/var/www# sudo apt-get remove wine1.4-amd64 ... After this operation, 216 MB disk space will be freed. Commented Jan 6, 2014 at 15:23

4 Answers 4

3

This was definitely an interesting question. It seems that the only thing I've ever seen give me the "XX will be freed" output is "apt-get remove". Even more oddly, it doesn't give you that line with the -s ("dry run") command line option.

WARNING[0]: That means that using apt-get to determine the output needs to run as root. So, for the love of Bob, MAKE SURE to test it on an expendable VM first!

WARNING[1]: Make sure you know what you're doing before you start removing packages. This will go through EVERY package on the system and see how much space would be recovered (as reported by apt-get) if it were removed. This doesn't mean they are SAFE to remove. I disclaim all responsibility!

Also worth mentioning: This will likely be very, very slow. Hopefully, this is something you're looking to run situationally, as the need arises, rather than repeatedly.

That said, I offer you my final kluge of 2013. Hopefully it helps.

#!/bin/bash 
for I in `dpkg --get-selections | grep install | grep -v adduser | grep -v apt | awk '{print $1}'`; 
do
    echo -n "$I : "
    apt-get --assume-no --purge remove $I | grep "will be freed" | awk '{print $4, $5}' >> ~/package_script.out
done

I wrote and tested it under ubuntu, so it should work fine for debian et al.

Update: I added a filter to remove the adduser and apt packages from consideration. The former is too "core" to remove and takes forever, the latter locks seemingly permanently. A There are probably more packages like that...

0
3
+50

You can also follow the same basic idea as suggested by @GeminiDomino but only for the packages you specify:

sudo apt-get --assume-no --purge remove PACKAGE | grep "will be freed" | 
  awk '{print $4, $5}' 

You can turn this into a function by adding these lines to your ~/.bashrc:

space_freed(){
    sudo apt-get --assume-no --purge remove "$@" | grep "freed.$" | 
      awk '{print $4, $5}' 
}

And then you can give multiple package names from the commandline:

$ space_freed thunderbird firefox chromium
239 MB

I had kind of assumed you would know the package names since otherwise this will take quite a while. Still, you could use my approach to list the sizes of all packages. This command will print the names of all installed packages:

$ dpkg -l | awk '($1=="ii"){print $2}'

If you run space_freed on each line output by that command, you will get a list of all installed packages and the space freed by uninstalling them:

for i in $(dpkg -l | awk '($1=="ii"){print $2}'); do  
 echo -e "$i\t"$(space_freed $i); 
done

The easiest way is to use wajig to list the largest installed packages:

wajig large
4
  • The question says the user doesn't know the package names in advance.
    – user89272
    Commented Jan 3, 2014 at 4:20
  • @ekaj: The purpose of comments is to suggest how an answer can be improved. I have done so. I didn't suggest deleting it. ☺
    – user89272
    Commented Jan 3, 2014 at 23:15
  • @ekaj in any case, she's the OP so it's her prerogative, thanks for sticking up for me though!
    – terdon
    Commented Jan 3, 2014 at 23:18
  • @Svetlana see updated answer for a way to run it for all packages.
    – terdon
    Commented Jan 3, 2014 at 23:40
2

Displaying package sizes

Synaptic :

Go to "Settings>Preferences" and choose "Columns and Fonts", then tick "Installed size".

dpkg-query :

dpkg-query --showformat='${Package}\n${Description}' -W {package-names/patterns}


Displaying largest installed packages (source)

dpkg-query -Wf '${Installed-Size}\t${Package}\n' | sort -n

wajig large

dpigs

sed -ne '/^Package: \(.*\)/{s//\1/;h;};/^Installed-Size: \(.*\)/{s//\1/;G;s/\n/ /;p;}' /var/lib/dpkg/status | sort -rn

awk '{if ($1 ~ /Package/) p = $2; if ($1 ~ /Installed/) printf("%9d %s\n", $2, p)}' /var/lib/dpkg/status | sort -n | tail
6
  • 1
    Are you sure Synaptic displays the what-if-I-purge-this size, not the what-if-I-remove-this-one-package size?
    – user89272
    Commented Jan 3, 2014 at 23:16
  • If you mean the difference between "remove" and "purge", which is basically just the configuration file, then I don't rightly know. My feeling is that "Installed size" should be all that was installed, meaning purge-size. As your problem is with large installations, I don't think this matters much.
    – harrymc
    Commented Jan 4, 2014 at 11:29
  • 1
    Yes, I mean difference between remove and purge. Please try to check what Synaptic shows.
    – user89272
    Commented Jan 5, 2014 at 22:35
  • If the problem is that you want the size including dependency packages, then I don't believe Synaptic does that, or any other package manager. See this link for using deborphan to delete orphaned packages, as well as this one.
    – harrymc
    Commented Jan 6, 2014 at 7:08
  • Orphaned packages are not what the question asks about. Nor are remove'ish package sizes. Nor are orphaned packages; they are related, but they don't answer the question. (I already checked, with lyx being a problem because of lots of tex fonts it needs for example, while it's not orphaned; deborphan wouldn't show that.)
    – user89272
    Commented Jan 7, 2014 at 5:52
0

Give aptitude a try... it's a cli based package manager with easy to use keybindgs. You can see how much space will be freed by purging a set of packages in the upper right corner of the interface.

You must log in to answer this question.