<?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>GL.IB.LY &#187; find</title>
	<atom:link href="http://gl.ib.ly/tag/find/feed/" rel="self" type="application/rss+xml" />
	<link>http://gl.ib.ly</link>
	<description>Thoughts on security, computing, business and stuff!</description>
	<lastBuildDate>Sun, 18 May 2014 11:51:56 +0000</lastBuildDate>
	<language>en-US</language>
		<sy:updatePeriod>hourly</sy:updatePeriod>
		<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.9.1</generator>
	<item>
		<title>Encoding audio and removing file extensions from files</title>
		<link>http://gl.ib.ly/stuff/2009/07/24/encoding-audio-removing-file-extensions-files/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=encoding-audio-removing-file-extensions-files</link>
		<comments>http://gl.ib.ly/stuff/2009/07/24/encoding-audio-removing-file-extensions-files/#comments</comments>
		<pubDate>Fri, 24 Jul 2009 06:41:28 +0000</pubDate>
		<dc:creator><![CDATA[tariq]]></dc:creator>
				<category><![CDATA[Stuff]]></category>
		<category><![CDATA[ffmpeg]]></category>
		<category><![CDATA[find]]></category>
		<category><![CDATA[moving]]></category>
		<category><![CDATA[one liners]]></category>
		<category><![CDATA[optimisation]]></category>
		<category><![CDATA[renaming]]></category>
		<category><![CDATA[sed]]></category>
		<category><![CDATA[sh]]></category>

		<guid isPermaLink="false">http://gl.ib.ly/?p=43</guid>
		<description><![CDATA[<p>Earlier today I got a massive SCORM object that contained lots of mp3 files. They were all high quality files, so I wanted to cut them down in size for web use. For this purpose I am using ffmpeg which you can<span class="ellipsis">&#8230;</span><div class="read-more"><a href="http://gl.ib.ly/stuff/2009/07/24/encoding-audio-removing-file-extensions-files/">Read more &#8250;</a></div><!-- end of .read-more --></p><p>The post <a href="http://gl.ib.ly/stuff/2009/07/24/encoding-audio-removing-file-extensions-files/">Encoding audio and removing file extensions from files</a> appeared first on <a href="http://gl.ib.ly">GL.IB.LY</a>.</p>]]></description>
				<content:encoded><![CDATA[<p>Earlier today I got a massive SCORM object that contained lots of mp3 files. They were all high quality files, so I wanted to cut them down in size for web use. For this purpose I am using <a title="http://ffmpeg.org/" href="http://web.archive.org/web/20100516171703/http://gl.ib.ly/exit.php?url_id=80&amp;entry_id=34">ffmpeg</a> which you can easily get for Windows, Linux or Mac. I tried the following on a Mac, but it should also work on Linux (paths permitting) and on Windows if you are using something like <a title="http://www.cygwin.com/" href="http://web.archive.org/web/20100516171703/http://gl.ib.ly/exit.php?url_id=81&amp;entry_id=34">cygwin</a>.</p>
<p>I <em>highly</em> recommend you get familiar with ffmpeg as it is amazingly useful. Just check out the <a title="http://linux.die.net/man/1/ffmpeg" href="http://web.archive.org/web/20100516171703/http://gl.ib.ly/exit.php?url_id=82&amp;entry_id=34">man pages</a>; swf to avi, avi to something that works on ipods, all a breeze!</p>
<div>So lets start and end with entering the directory which contains all our audio files on the command line. Once inside this directory we can use:</p>
<div>
<pre>find . -type f -name *.mp3 -exec ffmpeg -i {} -ac 1 -ab 32k {}32kb_m.mp3 \;</pre>
</div>
<p>Now, as you can see, I have created a new file for each original file. Each new file&#8217;s name is appended with 32kb_m.mp3 which tells me information about how the new mp3 file is encoded and gives hints to ffmpeg as to the files format (mp3 and encoder). Let me explain a little about the command. With <code>find</code> we are saying <i>find stuff in the current directory which are files and end in &#8220;.mp3&#8243; and when you find them execute ffmpeg.</i> The {} bit is expanded with whatever file <code>find</code>found. With the <code>ffmpeg</code> bit we are saying <i>our lord of ffmpeg please take as input this file from<code>find</code>&#8216;s output and set the number of audio channels to 1 and the bitrate to 32kbp/s and then output the file using the settings to a file whose filename is the same as our input file but has 32kb_m.mp3 added to end</i>.</p>
<p>Now we have created our new files and checked everything is ok (you should have those audios backed up somewhere too) we want to move all these new files to the locations of the originals. Our command moves/renames the files, removing part of the filename, recursively. Here it is:</p>
<pre>find . -type f -name *32kb_m.mp3 | sed 's/\(.*\)32kb_m.mp3/mv "\132kb_m.mp3" "\1"/' | sh</pre>
<p>So, again we use find! Here we are saying <i>find, in the current directory, all files with file names ending in &#8220;32kb_m.mp3&#8243; </i>. Here we are only, hopefully, pulling out our newly created files. Next we pipe all this data to <code>sed</code>. We tell <code>sed</code>: <i>hey Mr. Sed, look for any set of characters that are followed with &#8220;32kb_m.mp3&#8243; and replace the entire string (including 32kb_m.mp3) with &#8220;mv [the bit matched before 32kb_m.mp3]32kb_m.mp3 [the bit matched before 32kb_m.mp3]&#8220;</i>. Very simple, I hope! We are taking the big list from the output of find and using sed to transform the output into lots of <code>mv</code> commands. If we pipe these commands to <code>sh</code> then all those commands get executed. Hey presto, we&#8217;re done!</p>
<h2>How much space did you save?</h2>
<p>All my mp3s were in &#8216;audio&#8217; which I copied to &#8216;audio_32kb_m&#8217;. I then entered audio_32kb_m by cding into it and executing the commands above. Below is the output from <code>du</code> which tells me the total size of my audio directories. Size reduction is around 75%.</p>
<pre>snapple:/tmp tariq$ du -hs audio*
 33M	audio
8.5M	audio_32kb_m</pre>
</div>
<p>The post <a href="http://gl.ib.ly/stuff/2009/07/24/encoding-audio-removing-file-extensions-files/">Encoding audio and removing file extensions from files</a> appeared first on <a href="http://gl.ib.ly">GL.IB.LY</a>.</p>]]></content:encoded>
			<wfw:commentRss>http://gl.ib.ly/stuff/2009/07/24/encoding-audio-removing-file-extensions-files/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Searching compressed Apache logs</title>
		<link>http://gl.ib.ly/stuff/2009/06/23/searching-compressed-apache-logs/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=searching-compressed-apache-logs</link>
		<comments>http://gl.ib.ly/stuff/2009/06/23/searching-compressed-apache-logs/#comments</comments>
		<pubDate>Tue, 23 Jun 2009 06:27:23 +0000</pubDate>
		<dc:creator><![CDATA[tariq]]></dc:creator>
				<category><![CDATA[Stuff]]></category>
		<category><![CDATA[apache]]></category>
		<category><![CDATA[bunzip2]]></category>
		<category><![CDATA[compressed]]></category>
		<category><![CDATA[find]]></category>
		<category><![CDATA[grep]]></category>
		<category><![CDATA[gzip]]></category>
		<category><![CDATA[logs]]></category>
		<category><![CDATA[one liners]]></category>
		<category><![CDATA[tidbits]]></category>
		<category><![CDATA[xargs]]></category>

		<guid isPermaLink="false">http://gl.ib.ly/?p=35</guid>
		<description><![CDATA[<p>From time to time things tend to go wrong and systems tend to go crazy. Sometimes these errors are more of nuisance than anything else, an intermittent annoyance you&#8217;d prefer not to investigate &#8212; trawling through logs is a pain in<span class="ellipsis">&#8230;</span><div class="read-more"><a href="http://gl.ib.ly/stuff/2009/06/23/searching-compressed-apache-logs/">Read more &#8250;</a></div><!-- end of .read-more --></p><p>The post <a href="http://gl.ib.ly/stuff/2009/06/23/searching-compressed-apache-logs/">Searching compressed Apache logs</a> appeared first on <a href="http://gl.ib.ly">GL.IB.LY</a>.</p>]]></description>
				<content:encoded><![CDATA[<p>From time to time things tend to go wrong and <a title="http://gl.ib.ly/archives/10-Deleting-specific-emails-from-the-postfix-mail-queue.html" href="http://web.archive.org/web/20090814080809/http://gl.ib.ly/exit.php?url_id=65&amp;entry_id=27">systems tend to go crazy</a>. Sometimes these errors are more of nuisance than anything else, an intermittent annoyance you&#8217;d prefer not to investigate &#8212; trawling through logs is a pain in the backside. Now you need to take a peak at those compressed Apache error log files, ugh! Well before you look for suitable places to hang some rope try running some expressions across a certain number of files. Normally you&#8217;d only want to look at logs for the last 7 days, so lets give that a go.</p>
<div>The error messages I am interested in all contain the text <code>Healthcheck</code> so I will use trusty <code>grep</code>find matching lines in the logs. I will use <code>find</code> to get me all the files modified in the last seven days. A program called <code>xargs</code> will then be used to call <code>cat</code> which will pipe to a compression program which finally pipes to <code>grep</code>. Put this all together and you get something like this:</p>
<div>
<pre>find /var/log/apache2 -type f -name "error_*.bz2" -mtime -7 | sort | xargs cat | bunzip2 | grep"Healthcheck"</pre>
</div>
<p>If your files are <i>tar.gz</i> then you&#8217;ll need to replace <code>bunzip2</code> with gzip -dc. So that would look like:</p>
</div>
<div>
<pre>find /var/log/apache2 -type f -name "error_*.tar.gz" -mtime -7 | sort | xargs cat | gzip -dc |grep "Healthcheck"</pre>
<p>Have fun!</p>
</div>
<p>The post <a href="http://gl.ib.ly/stuff/2009/06/23/searching-compressed-apache-logs/">Searching compressed Apache logs</a> appeared first on <a href="http://gl.ib.ly">GL.IB.LY</a>.</p>]]></content:encoded>
			<wfw:commentRss>http://gl.ib.ly/stuff/2009/06/23/searching-compressed-apache-logs/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
