Ubuntu – 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?

Best Answer

  • 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)