apt-get remove with wildcard removed way more than expected. why?

Last night I was trying to burn CDs. Being annoyed with k3b and choosing to use brasero instead, I went to remove k3b.

I typed in:

sudo apt-get remove k3b

I hit tab twice and saw that I had both k3b and k3b-data on my system. Assuming that I wouldn't need k3b-data on my system without k3b, I wanted to remove it as well so I typed in:

sudo apt-get remove k3b*

Unfortunately I hit Y to confirm without looking. It uninstalled a whole lot more than k3b and k3b-data. It uninstalled packages which did not fit my k3b* regex. For example: transmission and network-manager.

I'm fairly certain that I didn't have a space between k3b and * but I don't know why else it would remove all that it did. Is there something about apt-get that I'm misunderstanding?


The command you want is sudo apt-get remove '^k3b.*', because:

  • You need .* to match any character, any number of times
  • You need ^ to match the start of the string
  • You need to quote the regex to prevent bash from interpreting * as a wildcard

(This answer completes and summarizes previous info provided by qbi and Flimm)


The regular expression * stands for zero or arbitrarily many. So you told apt-get to remove anything which contains k3 followed by any number of b, so basically everything which contains k3. If I try your command on my system it wants to remove 58 packages.

sudo apt-get remove -s k3b*
Package k3b is not installed, so not removed
Package k3b-data is not installed, so not removed
Package k3b-dbg is not installed, so not removed
Package libcanberra-gtk3-0 is not installed, so not removed
Package libcanberra-gtk3-0-dbg is not installed, so not removed
Package libcanberra-gtk3-dev is not installed, so not removed
…
The following packages will be REMOVED:
  appmenu-gtk ardour audacity brasero brasero-cdrkit firefox-globalmenu
  gconf-editor gir1.2-appindicator-0.1 gnome-applets gnome-control-center
…
0 upgraded, 2 newly installed, 58 to remove and 0 not upgraded.