Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

I have a text file with a package on each line. How can I remove all the packages in that text file from the system?

Also, if one package cannot be removes/wasn't installed in the first place can I make is continue.

What I would ideally like is an sudo apt-get remove packages.txt type solution.

share|improve this question
    
Others answered you, But careful in using apt-get or so on for removing. I prefer to use dpkg --purge MYPACKAGE , because remove just remove and --purge remove files and control files.Second note is dependecies , did you check them? –  Mohsen Pahlevanzadeh Aug 30 '12 at 18:41
    
@seg_fault The ability to delete configuration files with package removal (which is what --purge does) isn't specific to dpkg. You can also use sudo apt-get purge packagename or (equivalently) sudo apt-get --purge remove packagename. Furthermore, you will often not want to remove configuration files, as they take up very little space and you might want to reinstall the package (and have it use the previous configuration) in the future. –  Eliah Kagan Aug 30 '12 at 23:51
    
I'm sure that dpkg has --purge. –  Mohsen Pahlevanzadeh Aug 31 '12 at 18:55
add comment

2 Answers 2

up vote 4 down vote accepted

You could try:

sudo apt-get remove `cat packages.txt`

This should ignore packages that you don't have installed. I'm not sure what would happen if a package "cannot be removed" (since I've never seen this happen before).

Be sure to inspect the "The following packages will be REMOVED:" list to ensure nothing unexpected is removed.

share|improve this answer
    
+1, but backticks are evil :). use $(cat packages.txt) instead. –  cas Aug 30 '12 at 22:50
add comment

Updated:

If the package list is added in FILE1 and you want to remove all of them then:

#!/bin/sh
for i in \`cat $1`
do
       dpkg -${2} $i
done

Now save this file as script.sh and execute it with two parameter i. Name of the file in question ii. "r" for removal and "i" for installation

share|improve this answer
    
Explanation please? –  njallam Aug 30 '12 at 14:04
    
For every single package, mentioned per line in file, will be deleted. What else you are seeking for ? –  SHW Aug 30 '12 at 14:05
    
Can you please add how this would be implemented. Also seeing as this is going to be a .sh file. Can you make it take the file as the parameter? –  njallam Aug 30 '12 at 14:06
    
Check updated answer –  SHW Aug 30 '12 at 14:11
    
this will be horribly slow, as it will run dpkg for each package/file individually. Also the 'i' install option will only work on filenames, not package names...and even if you have all the files already downloaded and ready to install, the install may fail due to unsatisfied dependencies. Similarly, the 'r' remove option may fail if you try to remove a package which another installed package depends upon. lk-'s apt-get solution is much better. –  cas Aug 30 '12 at 22:48
show 1 more comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.