LinuxQuestions.org
Review your favorite Linux distribution.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Debian
User Name
Password
Debian This forum is for the discussion of Debian Linux.

Notices


Reply
  Search this Thread
Old 06-18-2008, 12:19 PM   #1
kushalkoolwal
Senior Member
 
Registered: Feb 2004
Location: Middle of nowhere
Distribution: Debian Squeeze
Posts: 1,249

Rep: Reputation: 49
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.
 
Old 06-18-2008, 12:38 PM   #2
scubanator87
Member
 
Registered: Jun 2007
Posts: 39

Rep: Reputation: Disabled
Lightbulb 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
 
Old 06-18-2008, 12:50 PM   #3
makuyl
Senior Member
 
Registered: Dec 2004
Location: Helsinki
Distribution: Debian Sid
Posts: 1,107

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

Last edited by makuyl; 06-18-2008 at 12:57 PM.
 
Old 06-18-2008, 01:30 PM   #4
kushalkoolwal
Senior Member
 
Registered: Feb 2004
Location: Middle of nowhere
Distribution: Debian Squeeze
Posts: 1,249

Original Poster
Rep: Reputation: 49
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.
 
Old 06-18-2008, 01:40 PM   #5
makuyl
Senior Member
 
Registered: Dec 2004
Location: Helsinki
Distribution: Debian Sid
Posts: 1,107

Rep: Reputation: 54
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`
 
Old 06-18-2008, 02:46 PM   #6
kushalkoolwal
Senior Member
 
Registered: Feb 2004
Location: Middle of nowhere
Distribution: Debian Squeeze
Posts: 1,249

Original Poster
Rep: Reputation: 49
Quote:
Originally Posted by makuyl View Post
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.
 
Old 06-18-2008, 03:02 PM   #7
farslayer
LQ Guru
 
Registered: Oct 2005
Location: Northeast Ohio
Distribution: linuxdebian
Posts: 7,249
Blog Entries: 5

Rep: Reputation: 191Reputation: 191
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.
 
Old 06-18-2008, 03:18 PM   #8
Telemachos
Member
 
Registered: May 2007
Distribution: Debian
Posts: 754

Rep: Reputation: 60
Quote:
Originally Posted by farslayer View Post
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
 
Old 06-18-2008, 07:34 PM   #9
farslayer
LQ Guru
 
Registered: Oct 2005
Location: Northeast Ohio
Distribution: linuxdebian
Posts: 7,249
Blog Entries: 5

Rep: Reputation: 191Reputation: 191
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 ?
 
Old 06-19-2008, 07:27 AM   #10
makuyl
Senior Member
 
Registered: Dec 2004
Location: Helsinki
Distribution: Debian Sid
Posts: 1,107

Rep: Reputation: 54
Quote:
Originally Posted by Telemachos View Post
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.

Last edited by makuyl; 06-19-2008 at 07:28 AM.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Getting "Short read in buffer_copy" error with "dpkg" stalefries Linux - Software 6 03-24-2010 03:19 PM
Stupid question: if [ "$i" == `$(cat ${LOGFILESSHD} | grep "${i}" )` ] ; then frenchn00b Programming 6 05-19-2008 05:16 PM
Standard commands give "-bash: open: command not found" even in "su -" and "su root" mibo12 Linux - General 4 11-11-2007 10:18 PM
LXer: Displaying "MyComputer", "Trash", "Network Servers" Icons On A GNOME Desktop LXer Syndicated Linux News 0 04-02-2007 08:31 AM
bash format "cat" output bendeco13 Linux - General 3 10-29-2004 06:39 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Debian

All times are GMT -5. The time now is 05:03 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration