Debian : How to remove all packages owning /some/folder/somefile

55 views
Skip to first unread message

Maxim Vexler

unread,
Mar 20, 2006, 6:04:03 PM3/20/06
to bash...@googlegroups.com
Hi folks,

This one is for the debianers among us:

If you have some obscure packages spreading their pesky .conf files
all around your system and you just know your about to get the urge to
purge, here's a one-liner that should do this for you.

-== Purging all packages based on (file | path) parameter ==-

1. You should have the package `apt-file` installed for this to
succeed. If you don't just run: <<< aptitude install apt-file >>>
2. Make sure you keep your apt-file cache updated by issuing the
following command <<< apt-file update >>>

Now, let (theoretical) assume you had enough with apache2 and decide
to revert back to the proven stability of apache 1.3. You could start
search for every apache2 lib/module you might have installed but that
is no brainer, plus were talking about Linux remember...

There's got to be a better solution, and indeed there is!

To purge all the packages that might have putted their files in /etc/apache2 :
<<<
for pkg in `apt-file search /etc/apache2/ | awk -F: { print $1 } |
sort | uniq`; do aptitude -y purge "$pkg"; done
>>>

This command will take some time to execute, but at the end you'll end
up with a sweeped system without even a small clue of apache2 ever
existed.


How the command works ?

1. for pkg in `XYD`; do ABD "$pkg"; done - This is a simple bash loop.
2. The back tic (``) are a "reverse pipe" mechanism in bash, basically
what that means it that any output from the commands inside the (`) is
redirected as input to the calling command.
3. apt-file search /foo/bar - Get any file matching the search pattern /foo/bar
4. awk -F: { print $1 } - Print only the first field (in our case the
PackageName).
5. sort - This one is for uniq to be able to filter all the
duplicates, otherwise thats really not needed here.
6. uniq - Make sure we only purge 1 time each package that matched.
7. aptitude -y purge "$pkg" - The (-y) = (yes) to any "normal" user
question ( Would you like to buy me a new Wide Screen TV? YES!!)

End of story, thanks to the magnificent power of the dpkg & apt
systems in debian a complex task such as (cleanly) removing all sorts
of software from your system, that would take a considerable amount of
time and effort on any other "User (NOT) friendly OS" becomes a simple
matter of a few piped shell commands.


"I hope this been informative for you, I wanna thank you for viewing" ;)


Obviously any comments, suggestions or improvements are welcome.

--
Cheers,
Maxim Vexler (hq4ever).

Do u GNU ?

Reply all
Reply to author
Forward
0 new messages