LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Debian (https://www.linuxquestions.org/questions/debian-26/)
-   -   Feeding the output of "diff" or "cat" command to dpkg --purge (https://www.linuxquestions.org/questions/debian-26/feeding-the-output-of-diff-or-cat-command-to-dpkg-purge-650110/)

kushalkoolwal 06-18-2008 12:19 PM

Feeding the output of "diff" or "cat" command to dpkg --purge
 
I created a list of packages installed on my system (say A) with the following command:

Code:

dpkg --get-selections > packages_on_A.txt
and then I did for another one (say B)
Code:

dpkg --get-selections > packages_on_B.txt

Then I diff'ed the above two files:

Code:

diff packages_on_A.txt packages_on_B.txt
to get a output like this:
Code:

splashy
libsplashy
lm-sensors
libsensors4

Basically I would like to now remove all the above package using dpkg --purge.

I can do it manually by running dpkg --purge couple of times. But I was wondering if there is any way by which I can pass the output of the diff command to dpkg --purge as arguments.

I know this is a very trial task but somehow I am not able to figure out.

I am using Debian etch (stable). I use apt-get and I DON'T intend to use aptitude or dselect.

scubanator87 06-18-2008 12:38 PM

Shell scripting
 
you could create a shell script with something like this in it

Code:

#!/bin/bash

file1=diff-output.txt

for f in `cat $file1`;
do
    echo "$f is being removed"
    echo "---------------------------------"
    dpkg --purge $f
    echo "*********************************"
    echo "$f has been removed"

done

This will work as long as only the file names are in the diff file, i had to use the cut command (you could also use awk) to select only the row of the package names.

Hope this helps and don't forget to make this file executable using

Code:

chmod +x uninstall.sh

makuyl 06-18-2008 12:50 PM

Try with: dpkg -P `diff packages_on_A.txt packages_on_B.txt | awk '{print $2}'|sed -e '1d'`
NB, those are backticks.

kushalkoolwal 06-18-2008 01:30 PM

Thank you guys for your inputs. I would try not to use shell script because that will mean that I have to carry/copy the script where ever I do this. I have to do this on a regular basis on 10s of systems so would be nice to have a simple command line.

makuyl 06-18-2008 01:40 PM

If you want to skip awk and sed you can do it manually in steps:
Code:

diff packages_on_A.txt packages_on_B.txt > packdiff
edit out the first line and keep the second column and do:
Code:

dpkg -P `cat packdiff`

kushalkoolwal 06-18-2008 02:46 PM

Quote:

Originally Posted by makuyl (Post 3188426)
If you want to skip awk and sed you can do it manually in steps:
Code:

diff packages_on_A.txt packages_on_B.txt > packdiff
edit out the first line and keep the second column and do:
Code:

dpkg -P `cat packdiff`

Looks like that worked!

Thanks Makuyl.

farslayer 06-18-2008 03:02 PM

could have just used the standard dselect-upgrade method to make the package sets match

dpkg --get selections > selections.txt on the box you want as the master package list..

dpkg --set-selections < selections.txt - Sets the package list on the new machine to match the list you created

apt-get dselect-upgrade - on the new machine

Quote:

dselect-upgrade
dselect-upgrade is used in conjunction with the traditional Debian packaging front-end, dselect(8). dselect-upgrade follows the changes made by dselect(8) to the Status field of available packages, and performs the actions necessary to realize that state (for instance, the removal of old and the installation of new packages).
http://linux.die.net/man/8/apt-get


No it's not a purge but a few config files don't add up to much.

Telemachos 06-18-2008 03:18 PM

Quote:

Originally Posted by farslayer (Post 3188523)
No it's not a purge but a few config files don't add up to much.

You can also use aptitude to clear out uninstalled but not purged packages:
Quote:

aptitude purge ~c
Though if you have been using apt-get only up until that time (especially in Etch), you should run this first
Quote:

aptitude keep-all

farslayer 06-18-2008 07:34 PM

Nice..

I was looking to see if aptitude supported the dselect-upgrade function and I was unable to find mention of support for that command in the docs.. do you know of a way to do that function with aptitude ?

makuyl 06-19-2008 07:27 AM

Quote:

Originally Posted by Telemachos (Post 3188535)
You can also use aptitude to clear out uninstalled but not purged packages:
Though if you have been using apt-get only up until that time (especially in Etch), you should run this first

The OP did say in his first post:
Quote:

I use apt-get and I DON'T intend to use aptitude or dselect.
So using dpkg to purge removed packages I suppose it would be something like:
Code:

sudo dpkg -P `dpkg -l|grep ^r|awk '{print $2}'`
Again, it doesn't need to be a one liner. Don't know how to do that with apt-get though, except for installing a removed package and then purging it. Aptitude is not an option for me either.


All times are GMT -5. The time now is 11:51 PM.