<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Wojciech Jamrozy blog &#187; purging</title>
	<atom:link href="http://www.wojtekrj.net/tag/purging/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.wojtekrj.net</link>
	<description>Blog about computer science, programming and linux</description>
	<lastBuildDate>Sun, 23 Oct 2011 21:57:23 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>[Ubuntu] Packages auto-purging script</title>
		<link>http://www.wojtekrj.net/2009/08/ubuntu-packages-auto-purging-script/</link>
		<comments>http://www.wojtekrj.net/2009/08/ubuntu-packages-auto-purging-script/#comments</comments>
		<pubDate>Tue, 11 Aug 2009 17:02:53 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Bash]]></category>
		<category><![CDATA[Ubuntu]]></category>
		<category><![CDATA[bash]]></category>
		<category><![CDATA[packages]]></category>
		<category><![CDATA[purging]]></category>

		<guid isPermaLink="false">http://www.wojtekrj.net/?p=219</guid>
		<description><![CDATA[Here is my script for auto-purging of removed packages (the script deletes remaining configuration files of package) in Ubuntu: #!/bin/sh for i in `dpkg -l &#124; grep ^rc &#124; cut -f 3 -d ' '` do dpkg -P $i; done dpkg -l shows list of packages installed in system grep ^rc print all lines starting [...]]]></description>
			<content:encoded><![CDATA[<p>Here is my script for auto-purging of removed packages (the script deletes remaining configuration files of package) in Ubuntu:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">#!/bin/sh</span>
<span style="color: #000000; font-weight: bold;">for</span> i <span style="color: #000000; font-weight: bold;">in</span> <span style="color: #000000; font-weight: bold;">`</span><span style="color: #c20cb9; font-weight: bold;">dpkg</span> <span style="color: #660033;">-l</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">grep</span> ^rc <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">cut</span> <span style="color: #660033;">-f</span> <span style="color: #000000;">3</span> <span style="color: #660033;">-d</span> <span style="color: #ff0000;">' '</span><span style="color: #000000; font-weight: bold;">`</span>
<span style="color: #000000; font-weight: bold;">do</span>
    <span style="color: #c20cb9; font-weight: bold;">dpkg</span> <span style="color: #660033;">-P</span> <span style="color: #007800;">$i</span>;
<span style="color: #000000; font-weight: bold;">done</span></pre></div></div>

<p><span id="more-219"></span><br />
<em>dpkg -l</em>  shows list of packages installed in system<br />
<em>grep ^rc </em>   print all lines starting with &#8220;rc&#8221; (in this case print all lines with name of packages which configuration files are still in system)<br />
<em>cut -f 3 -d &#8216; &#8216;</em> Divides lines into fields using space as delimiter and prints 3rd field (in this case retrieve name of packages to delete)<br />
<em>dpkg -P package</em> purges <em>package</em><br />
This <a href="http://www.wojtekrj.net/2009/07/bash-how-to-iterate-over-lines-of-standard-output-of-command/">link</a> explains other things.<br />
Script can also be added to /etc/crontab as:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">09 <span style="color: #000000;">18</span> <span style="color: #000000; font-weight: bold;">*</span> <span style="color: #000000; font-weight: bold;">*</span> <span style="color: #000000; font-weight: bold;">*</span> root <span style="color: #000000; font-weight: bold;">for</span> i <span style="color: #000000; font-weight: bold;">in</span> <span style="color: #000000; font-weight: bold;">`</span><span style="color: #c20cb9; font-weight: bold;">dpkg</span> <span style="color: #660033;">-l</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">grep</span> ^rc <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">cut</span> <span style="color: #660033;">-f</span> <span style="color: #000000;">3</span> <span style="color: #660033;">-d</span> <span style="color: #ff0000;">' '</span><span style="color: #000000; font-weight: bold;">`</span>; <span style="color: #000000; font-weight: bold;">do</span> <span style="color: #c20cb9; font-weight: bold;">dpkg</span> <span style="color: #660033;">-P</span> <span style="color: #007800;">$i</span>; <span style="color: #000000; font-weight: bold;">done</span></pre></div></div>

<p>Script will be executed with root privileges everyday at 18:09.</p>
<p><a class="a2a_button_wykop" href="http://www.addtoany.com/add_to/wykop?linkurl=http%3A%2F%2Fwww.wojtekrj.net%2F2009%2F08%2Fubuntu-packages-auto-purging-script%2F&amp;linkname=%5BUbuntu%5D%20Packages%20auto-purging%20script" title="Wykop" rel="nofollow" target="_blank"><img src="http://www.wojtekrj.net/wp-content/plugins/add-to-any/icons/wykop.png" width="16" height="16" alt="Wykop"/></a><a class="a2a_button_delicious" href="http://www.addtoany.com/add_to/delicious?linkurl=http%3A%2F%2Fwww.wojtekrj.net%2F2009%2F08%2Fubuntu-packages-auto-purging-script%2F&amp;linkname=%5BUbuntu%5D%20Packages%20auto-purging%20script" title="Delicious" rel="nofollow" target="_blank"><img src="http://www.wojtekrj.net/wp-content/plugins/add-to-any/icons/delicious.png" width="16" height="16" alt="Delicious"/></a><a class="a2a_button_facebook" href="http://www.addtoany.com/add_to/facebook?linkurl=http%3A%2F%2Fwww.wojtekrj.net%2F2009%2F08%2Fubuntu-packages-auto-purging-script%2F&amp;linkname=%5BUbuntu%5D%20Packages%20auto-purging%20script" title="Facebook" rel="nofollow" target="_blank"><img src="http://www.wojtekrj.net/wp-content/plugins/add-to-any/icons/facebook.png" width="16" height="16" alt="Facebook"/></a><a class="a2a_button_technorati_favorites" href="http://www.addtoany.com/add_to/technorati_favorites?linkurl=http%3A%2F%2Fwww.wojtekrj.net%2F2009%2F08%2Fubuntu-packages-auto-purging-script%2F&amp;linkname=%5BUbuntu%5D%20Packages%20auto-purging%20script" title="Technorati Favorites" rel="nofollow" target="_blank"><img src="http://www.wojtekrj.net/wp-content/plugins/add-to-any/icons/technorati.png" width="16" height="16" alt="Technorati Favorites"/></a><a class="a2a_button_digg" href="http://www.addtoany.com/add_to/digg?linkurl=http%3A%2F%2Fwww.wojtekrj.net%2F2009%2F08%2Fubuntu-packages-auto-purging-script%2F&amp;linkname=%5BUbuntu%5D%20Packages%20auto-purging%20script" title="Digg" rel="nofollow" target="_blank"><img src="http://www.wojtekrj.net/wp-content/plugins/add-to-any/icons/digg.png" width="16" height="16" alt="Digg"/></a><a class="a2a_button_google_bookmarks" href="http://www.addtoany.com/add_to/google_bookmarks?linkurl=http%3A%2F%2Fwww.wojtekrj.net%2F2009%2F08%2Fubuntu-packages-auto-purging-script%2F&amp;linkname=%5BUbuntu%5D%20Packages%20auto-purging%20script" title="Google Bookmarks" rel="nofollow" target="_blank"><img src="http://www.wojtekrj.net/wp-content/plugins/add-to-any/icons/google.png" width="16" height="16" alt="Google Bookmarks"/></a><a class="a2a_button_msdn" href="http://www.addtoany.com/add_to/msdn?linkurl=http%3A%2F%2Fwww.wojtekrj.net%2F2009%2F08%2Fubuntu-packages-auto-purging-script%2F&amp;linkname=%5BUbuntu%5D%20Packages%20auto-purging%20script" title="MSDN" rel="nofollow" target="_blank"><img src="http://www.wojtekrj.net/wp-content/plugins/add-to-any/icons/msdn.png" width="16" height="16" alt="MSDN"/></a><a class="a2a_button_twitter" href="http://www.addtoany.com/add_to/twitter?linkurl=http%3A%2F%2Fwww.wojtekrj.net%2F2009%2F08%2Fubuntu-packages-auto-purging-script%2F&amp;linkname=%5BUbuntu%5D%20Packages%20auto-purging%20script" title="Twitter" rel="nofollow" target="_blank"><img src="http://www.wojtekrj.net/wp-content/plugins/add-to-any/icons/twitter.png" width="16" height="16" alt="Twitter"/></a><a class="a2a_button_technotizie" href="http://www.addtoany.com/add_to/technotizie?linkurl=http%3A%2F%2Fwww.wojtekrj.net%2F2009%2F08%2Fubuntu-packages-auto-purging-script%2F&amp;linkname=%5BUbuntu%5D%20Packages%20auto-purging%20script" title="Technotizie" rel="nofollow" target="_blank"><img src="http://www.wojtekrj.net/wp-content/plugins/add-to-any/icons/technotizie.png" width="16" height="16" alt="Technotizie"/></a><a class="a2a_button_technet" href="http://www.addtoany.com/add_to/technet?linkurl=http%3A%2F%2Fwww.wojtekrj.net%2F2009%2F08%2Fubuntu-packages-auto-purging-script%2F&amp;linkname=%5BUbuntu%5D%20Packages%20auto-purging%20script" title="TechNet" rel="nofollow" target="_blank"><img src="http://www.wojtekrj.net/wp-content/plugins/add-to-any/icons/technet.png" width="16" height="16" alt="TechNet"/></a><a class="a2a_dd a2a_target addtoany_share_save" href="http://www.addtoany.com/share_save#url=http%3A%2F%2Fwww.wojtekrj.net%2F2009%2F08%2Fubuntu-packages-auto-purging-script%2F&amp;title=%5BUbuntu%5D%20Packages%20auto-purging%20script" id="wpa2a_2">Share/Save</a></p>]]></content:encoded>
			<wfw:commentRss>http://www.wojtekrj.net/2009/08/ubuntu-packages-auto-purging-script/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

