<?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>Claus Witt &#187; bash</title> <atom:link href="http://www.clauswitt.com/tag/bash/feed/" rel="self" type="application/rss+xml" /><link>http://www.clauswitt.com</link> <description>software and web developer</description> <lastBuildDate>Thu, 24 Jun 2010 20:07:03 +0000</lastBuildDate> <generator>http://wordpress.org/?v=2.9.2</generator> <language>en</language> <sy:updatePeriod>hourly</sy:updatePeriod> <sy:updateFrequency>1</sy:updateFrequency> <item><title>Bash script for editing the hosts file</title><link>http://www.clauswitt.com/319/</link> <comments>http://www.clauswitt.com/319/#comments</comments> <pubDate>Wed, 04 Nov 2009 09:02:46 +0000</pubDate> <dc:creator>Claus Witt</dc:creator> <category><![CDATA[Web development]]></category> <category><![CDATA[bash]]></category> <category><![CDATA[easy creation]]></category> <category><![CDATA[hosts]]></category> <category><![CDATA[shell script]]></category><guid isPermaLink="false">http://www.clauswitt.com/?p=319</guid> <description><![CDATA[I just read a post about local development in apache by Jesper Rasmussen and thought one thing was missing. I usually test my sites and applications locally with the real domain &#8211; to ensure that functionality based on the url works as expected. However this means editing the hosts file several times a day. Now [...]]]></description> <content:encoded><![CDATA[<p>I just read a <a href="http://jesperrasmussen.com/coding-on-the-go-setting-up-local-apache">post about local development in apache</a> by <a href="http://jesperrasmussen.com/">Jesper Rasmussen</a> and thought one thing was missing. I usually test my sites and applications locally with the real domain &#8211; to ensure that functionality based on the url works as expected. However this means editing the hosts file several times a day. Now I have made a small shellscript that will add and remove lines from the hosts file.</p><pre name="code" class="bash">
#! /bin/bash
DEFAULT_IP=127.0.0.1
IP=${3:-$DEFAULT_IP}

case "$1" in
  add)
        echo "$IP $2"  >> /etc/hosts
        ;;
  remove)
        sed -ie "\|^$IP $2\$|d" /etc/hosts
        ;;

  *)
        echo "Usage: "
		echo "hosts.sh [add|remove] [hostname] [ip]"
		echo
		echo "Ip defaults to 127.0.0.1"
		echo "Examples:"
		echo "hosts.sh add testing.com"
		echo "hosts.sh remove testing.com 192.168.1.1"
        exit 1
        ;;
esac

exit 0
</pre><p>As you can see the script defaults the ip to 127.0.0.1 for easy creation of local domains. Next step is to create a quicksilver (and a gnome do) plugin for easy creation without ever touching the terminal. (Even though we all love the terminal, right?)</p> ]]></content:encoded> <wfw:commentRss>http://www.clauswitt.com/319/feed/</wfw:commentRss> <slash:comments>1</slash:comments> </item> <item><title>Converting Filenames to Lowercase with Bash</title><link>http://www.clauswitt.com/converting-filenames-to-lowercase-with-bash/</link> <comments>http://www.clauswitt.com/converting-filenames-to-lowercase-with-bash/#comments</comments> <pubDate>Wed, 03 Jun 2009 07:24:36 +0000</pubDate> <dc:creator>Claus Witt</dc:creator> <category><![CDATA[Development]]></category> <category><![CDATA[bash]]></category> <category><![CDATA[bash oneliner]]></category> <category><![CDATA[import script]]></category> <category><![CDATA[voicearchive]]></category><guid isPermaLink="false">http://www.clauswitt.com/?p=246</guid> <description><![CDATA[Once again I have a bash-oneliner. For some reason it is all I blog about at the moment. I had an import script for importing demo files (in mp3 format) to a database used at Voicearchive. Only problem the import script depended on the files being named precisely according to a specific rule. But for [...]]]></description> <content:encoded><![CDATA[<p>Once again I have a bash-oneliner. For some reason it is all I blog about at the moment.</p><p>I had an import script for importing demo files (in mp3 format) to a database used at <a href="http://www.voicearchive.com/">Voicearchive</a>. Only problem the import script depended on the files being named precisely according to a specific rule. But for some reason some times it was named with uppercase letters, and sometimes with lowercase letters. I decided to rename all files to lowercase, and change the importscript accordingly.</p><pre name="code" class="bash">
find . -maxdepth 1 -type f -execdir rename 'y/A-Z/a-z/' '{}' \;
</pre>]]></content:encoded> <wfw:commentRss>http://www.clauswitt.com/converting-filenames-to-lowercase-with-bash/feed/</wfw:commentRss> <slash:comments>0</slash:comments> </item> <item><title>Bash Oneliner for Counting Files</title><link>http://www.clauswitt.com/bash-oneliner-for-counting-files/</link> <comments>http://www.clauswitt.com/bash-oneliner-for-counting-files/#comments</comments> <pubDate>Thu, 14 May 2009 09:56:51 +0000</pubDate> <dc:creator>Claus Witt</dc:creator> <category><![CDATA[Development]]></category> <category><![CDATA[bash]]></category> <category><![CDATA[bash oneliner]]></category> <category><![CDATA[counting files]]></category><guid isPermaLink="false">http://www.clauswitt.com/?p=236</guid> <description><![CDATA[I needed to find a way to count the number of files in a directory and only output that number. Bash is still my best friend for this sort of thing &#8211; especially with a little help from google.ls -1 &#124; wc -lby the way &#8211; the answer was 2062 files. ]]></description> <content:encoded><![CDATA[<p>I needed to find a way to count the number of files in a directory and only output that number. Bash is still my best friend for this sort of thing &#8211; especially with a little help from google.</p><pre name="code" class="bash">
ls -1 | wc -l
</pre><p>by the way &#8211; the answer was 2062 files.</p> ]]></content:encoded> <wfw:commentRss>http://www.clauswitt.com/bash-oneliner-for-counting-files/feed/</wfw:commentRss> <slash:comments>2</slash:comments> </item> <item><title>Renaming file extensions with bash script</title><link>http://www.clauswitt.com/renaming-file-extensions-with-bash-script/</link> <comments>http://www.clauswitt.com/renaming-file-extensions-with-bash-script/#comments</comments> <pubDate>Thu, 30 Apr 2009 06:58:04 +0000</pubDate> <dc:creator>Claus Witt</dc:creator> <category><![CDATA[Development]]></category> <category><![CDATA[bash]]></category> <category><![CDATA[renaming file]]></category> <category><![CDATA[script]]></category> <category><![CDATA[short tips]]></category> <category><![CDATA[zend]]></category><guid isPermaLink="false">http://www.clauswitt.com/?p=230</guid> <description><![CDATA[A couple of weeks ago I had to rename the file extension of several view scripts from html (from my own mvc framework) to phtml (zend framework). I found, as always, bash to be my friend.for i in * do ( file $i &#124; grep html ) &#038;&#038; mv $i $(echo $i &#124; sed [...]]]></description> <content:encoded><![CDATA[<p>A couple of weeks ago I had to rename the file extension of several view scripts from html (from my own mvc framework) to phtml (zend framework). I found, as always, bash to be my friend.</p><pre name="code" class="bash">
for i in *
do
  ( file $i | grep html ) &#038;&#038; mv $i $(echo $i | sed s/html$/phtml/)
done
</pre>]]></content:encoded> <wfw:commentRss>http://www.clauswitt.com/renaming-file-extensions-with-bash-script/feed/</wfw:commentRss> <slash:comments>1</slash:comments> </item> <item><title>How I sorted All My Mp3&#8217;s With a Simple Bash Script</title><link>http://www.clauswitt.com/how-i-sorted-all-my-mp3s-with-a-simple-bash-script/</link> <comments>http://www.clauswitt.com/how-i-sorted-all-my-mp3s-with-a-simple-bash-script/#comments</comments> <pubDate>Thu, 12 Mar 2009 21:00:00 +0000</pubDate> <dc:creator>Claus Witt</dc:creator> <category><![CDATA[Development]]></category> <category><![CDATA[bash]]></category> <category><![CDATA[mp3]]></category><guid isPermaLink="false">http://www.clauswitt.com/?p=181</guid> <description><![CDATA[First of all, the headline is a lie. I am in the process of copying all mp3 files that we in our household have had on a number of different machines to one central server, which all computers talk to via webdav. But since we have had a lot of different naming schemes and ways [...]]]></description> <content:encoded><![CDATA[<p>First of all, the headline is a lie. I am in the process of copying all mp3 files that we in our household have had on a number of different machines to one central server, which all computers talk to via webdav. But since we have had a lot of different naming schemes and ways of sorting files we needed some sort of uniform naming of files and directories. We decided on the ever so nice /Artist/Album/01_Title.mp3. But since we have a lot of mp3&#8217;s, this seemed a daunting task.</p><p>In comes bash. 6 lines of code is all it takes.</p><pre name="code" class="bash">
#!/bin/bash
end="/destination/dir/of/mp3s"
find -type f -name *.mp3 -print0 | while read -d  $'\0' file; do
        mkdir --parent "$end"/"$(mp3info -f -p %a "$file")"/"$(mp3info -f -p %l "$file")"
        mv "$file" "$end"/"$(mp3info -f -p %a "$file")"/"$(mp3info -f -p %l "$file")"/"$(mp3info -f -p %n "$file")"_"$(mp3info -f -p %t "$file")".mp3
done
</pre><p>The small program mp3info is used to extract id3 tags from the files. (Fortunately they are entered for almost all files). I am not the greatest bash-hacker in the world, so there might be a better way to do this. But I have tested this, and it works, and is quite fast.</p><p>If you know of a better way to do this, please comment. I would love to learn.</p> ]]></content:encoded> <wfw:commentRss>http://www.clauswitt.com/how-i-sorted-all-my-mp3s-with-a-simple-bash-script/feed/</wfw:commentRss> <slash:comments>0</slash:comments> </item> </channel> </rss>
<!-- Performance optimized by W3 Total Cache. Learn more: http://www.w3-edge.com/wordpress-plugins/

Minified using memcached
Page Caching using memcached (user agent is rejected)
Database Caching using memcached

Served from: www.clauswitt.com @ 2010-07-30 04:27:51 -->