<?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>MrBrown blob &#187; Command line</title>
	<atom:link href="http://charles.lescampeurs.org/category/command-line/feed" rel="self" type="application/rss+xml" />
	<link>http://charles.lescampeurs.org</link>
	<description>random bits.</description>
	<lastBuildDate>Thu, 02 Feb 2012 14:34:09 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Find and remove files</title>
		<link>http://charles.lescampeurs.org/2010/02/04/find-and-remove-files?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=find-and-remove-files</link>
		<comments>http://charles.lescampeurs.org/2010/02/04/find-and-remove-files#comments</comments>
		<pubDate>Thu, 04 Feb 2010 09:36:29 +0000</pubDate>
		<dc:creator>CharlyBr</dc:creator>
				<category><![CDATA[Command line]]></category>
		<category><![CDATA[find]]></category>

		<guid isPermaLink="false">http://charles.lescampeurs.org/?p=215</guid>
		<description><![CDATA[I regularly use the find command in scripts to clean directories on my servers. The common way to use find to do this is to write something like: find ./my_dir -name 'cache-*' -exec rm -rf \{\} \; It works fine but it always outputs messages like this: find: ./mydir/cache-001: No such file or director which [...]]]></description>
			<content:encoded><![CDATA[<p>I regularly use the find command in scripts to clean directories on my servers.<br /> The common way to use find to do this is to write something like:</p>
<pre>find ./my_dir -name 'cache-*' -exec rm -rf \{\} \;</pre>
<p>It works fine but it always outputs messages like this:</p>
<pre>find: ./mydir/cache-001: No such file or director</pre>
<p>which can be annoying when ran in a crontab.</p>
<p>I just found recently that using the option &#8216;-delete&#8217; with find just fix this problem.</p>
<pre>find ./my_dir -name 'cache-*' -delete</pre>
<p> </p>
<p> </p>
 <img src="http://charles.lescampeurs.org/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?view=1&post_id=215" width="1" height="1" style="display: none;" />]]></content:encoded>
			<wfw:commentRss>http://charles.lescampeurs.org/2010/02/04/find-and-remove-files/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Quickly check hosts with ping</title>
		<link>http://charles.lescampeurs.org/2009/08/14/quickly-check-hosts-with-ping?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=quickly-check-hosts-with-ping</link>
		<comments>http://charles.lescampeurs.org/2009/08/14/quickly-check-hosts-with-ping#comments</comments>
		<pubDate>Fri, 14 Aug 2009 11:46:02 +0000</pubDate>
		<dc:creator>CharlyBr</dc:creator>
				<category><![CDATA[Command line]]></category>
		<category><![CDATA[loop]]></category>
		<category><![CDATA[netcat]]></category>
		<category><![CDATA[ping]]></category>

		<guid isPermaLink="false">http://charles.lescampeurs.org/?p=198</guid>
		<description><![CDATA[I needed a script for a quick health check of a bunch of servers. This is how I did it using the ping command: for((i=1;i&#60;42;i++)); do ping -c 1 -W 3 host${i}.domain.com &#38;&#62; /dev/null if [ $? -ne 0 ] ; then echo "host${i} is down" else echo "host${i} is up" fi done You can [...]]]></description>
			<content:encoded><![CDATA[<p>I needed a script for a quick health check of a bunch of servers.<br />
This is how I did it using the <a href="http://linux.die.net/man/8/ping" target="_blank">ping command</a>:</p>
<pre>for((i=1;i&lt;42;i++)); do
    ping -c 1 -W 3 host${i}.domain.com &amp;&gt; /dev/null
    if [ $? -ne 0 ] ; then
        echo "host${i} is down"
    else
        echo "host${i} is up"
    fi
done</pre>
<p>You can also use netcat and check a specific port:</p>
<pre>netcat -z -w 2  host${i}.domain.com 80 &amp;&gt; /dev/null</pre>
 <img src="http://charles.lescampeurs.org/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?view=1&post_id=198" width="1" height="1" style="display: none;" />]]></content:encoded>
			<wfw:commentRss>http://charles.lescampeurs.org/2009/08/14/quickly-check-hosts-with-ping/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Set Terminal tab title in Mac OS X</title>
		<link>http://charles.lescampeurs.org/2009/08/11/set-terminal-tab-title-in-mac-os-x?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=set-terminal-tab-title-in-mac-os-x</link>
		<comments>http://charles.lescampeurs.org/2009/08/11/set-terminal-tab-title-in-mac-os-x#comments</comments>
		<pubDate>Tue, 11 Aug 2009 12:12:07 +0000</pubDate>
		<dc:creator>CharlyBr</dc:creator>
				<category><![CDATA[Command line]]></category>
		<category><![CDATA[shell]]></category>
		<category><![CDATA[terminal]]></category>

		<guid isPermaLink="false">http://charles.lescampeurs.org/?p=195</guid>
		<description><![CDATA[I wrote previously a how-to to set your iTerm tab title. I finally found a tool to do the same thing with the default Mac OS X Terminal. Check it out here, it works perfectly for me!  link is dead. On my Mac OS X 10.6.6 and bash (3.2.48(1)-release), you can set your tab title [...]]]></description>
			<content:encoded><![CDATA[<p><img class="aligncenter size-full wp-image-196" title="Picture 2" src="http://charles.lescampeurs.org/wp-content/uploads/2009/08/Picture-2.png" alt="Picture 2" width="209" height="84" /></p>
<p>I wrote previously a how-to to <a href="http://charles.lescampeurs.org/2008/05/07/automatically-set-title-on-iterm-tabs" target="_blank">set your iTerm tab title</a>.</p>
<p>I finally found a tool to do the same thing with the default Mac OS X Terminal.</p>
<p><strike>Check it out <a href="http://purpleamy.com/magicwrap/" target="_blank">here</a>, it works perfectly for me!</strike>  link is dead.</p>
<p>On my Mac OS X 10.6.6 and bash (3.2.48(1)-release), you can set your tab title with the PROMPT_COMMAND variable as follow:</p>
<p>export PROMPT_COMMAND=’echo -ne “\033]0;${USER}@${HOSTNAME%%.*}\007″‘</p>
<p>Add this to your <em>.bashrc</em> or <em>/etc/profile</em> file and you&#8217;re done <img src='http://charles.lescampeurs.org/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
 <img src="http://charles.lescampeurs.org/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?view=1&post_id=195" width="1" height="1" style="display: none;" />]]></content:encoded>
			<wfw:commentRss>http://charles.lescampeurs.org/2009/08/11/set-terminal-tab-title-in-mac-os-x/feed</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
		<item>
		<title>Finding the total size of a set of files with awk</title>
		<link>http://charles.lescampeurs.org/2009/04/17/finding-the-total-size-of-a-set-of-files-with-awk?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=finding-the-total-size-of-a-set-of-files-with-awk</link>
		<comments>http://charles.lescampeurs.org/2009/04/17/finding-the-total-size-of-a-set-of-files-with-awk#comments</comments>
		<pubDate>Fri, 17 Apr 2009 09:12:22 +0000</pubDate>
		<dc:creator>CharlyBr</dc:creator>
				<category><![CDATA[Command line]]></category>
		<category><![CDATA[awk]]></category>

		<guid isPermaLink="false">http://charles.lescampeurs.org/?p=185</guid>
		<description><![CDATA[If you need to sum the total size of files in a directory or matching a pattern, an easy solution is to use awk. I needed to calculate this total for a set of javascript files, I used this command line: $ find App/ -name '*.js' -exec ls -l \{\} \; &#124; awk '{sum+=$5} END [...]]]></description>
			<content:encoded><![CDATA[<p>If you need to sum the total size of files in a directory or matching a pattern, an easy solution is to use <em>awk</em>.</p>
<p>I needed to calculate this total for a set of javascript files, I used this command line:</p>
<pre>$ find App/ -name '*.js' -exec ls -l \{\} \; | awk '{sum+=$5} END {print sum}'
1929403</pre>
<p>For a human readable result, you can divide your result and use printf to format it:</p>
<pre>$ find App/ -name '*.js' -exec ls -l \{\} \; | awk '{sum+=$5} END {printf("%.2fM\n", sum/1024/1024)}'
1.84M</pre>
 <img src="http://charles.lescampeurs.org/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?view=1&post_id=185" width="1" height="1" style="display: none;" />]]></content:encoded>
			<wfw:commentRss>http://charles.lescampeurs.org/2009/04/17/finding-the-total-size-of-a-set-of-files-with-awk/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Memory usage by group of processes</title>
		<link>http://charles.lescampeurs.org/2009/03/13/memory-usage-by-group-of-processes?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=memory-usage-by-group-of-processes</link>
		<comments>http://charles.lescampeurs.org/2009/03/13/memory-usage-by-group-of-processes#comments</comments>
		<pubDate>Fri, 13 Mar 2009 14:14:26 +0000</pubDate>
		<dc:creator>CharlyBr</dc:creator>
				<category><![CDATA[Benchmarks]]></category>
		<category><![CDATA[Command line]]></category>
		<category><![CDATA[Monitoring]]></category>
		<category><![CDATA[awk]]></category>
		<category><![CDATA[memory]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[shell]]></category>

		<guid isPermaLink="false">http://charles.lescampeurs.org/?p=173</guid>
		<description><![CDATA[While monitoring a http/php server, I needed to do some statistics about php-cgi memory usage. Playing with memory_limit in PHP, we wanted to know the average memory usage per php-cgi process. This is easily calculated with our best friend awk. First, get the number of php running processes: # ps aux &#124; grep php-cgi &#124; [...]]]></description>
			<content:encoded><![CDATA[<p>While monitoring a http/php server, I needed to do some statistics about php-cgi memory usage.</p>
<p>Playing with <em>memory_limit</em> in PHP, we wanted to know the average memory usage per php-cgi process. This is easily calculated with our best friend awk.</p>
<p>First, get the number of php running processes:</p>
<pre># ps aux | grep php-cgi | grep -v grep | wc -l
126</pre>
<p>Then, use awk to calculate the average memory usage for these processes:</p>
<pre># ps aux | grep --exclude=grep php-cgi | grep -v grep | awk 'BEGIN{s=0;}{s=s+$6;}END{print s/126;}'
33987.8</pre>
<p>The number used in the calculation is the field RSS given by ps. The ps manual page says:</p>
<blockquote><p>rss: resident set size, the non-swapped physical memory that a task has used (in kiloBytes)</p></blockquote>
<p>You can also calculate the total memory used by all php-cgi processes:</p>
<pre># ps aux | grep --exclude=grep php-cgi | grep -v grep | awk 'BEGIN{s=0;}{s=s+$6;}END{print s;}'
4302028</pre>
<p>If you need to watch the trend of this average memory usage, a little shell loop does the trick:</p>
<pre># while [ 1 ]; do ps aux | grep --exclude=grep php-cgi | grep -v grep | awk 'BEGIN{s=0;}{s=s+$6;}END{print s/126;}'; sleep 2; done
34401.3
34405.1
34408.4
34409.4
34414.2
34417</pre>
 <img src="http://charles.lescampeurs.org/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?view=1&post_id=173" width="1" height="1" style="display: none;" />]]></content:encoded>
			<wfw:commentRss>http://charles.lescampeurs.org/2009/03/13/memory-usage-by-group-of-processes/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>The unix touch command</title>
		<link>http://charles.lescampeurs.org/2008/09/11/the-unix-touch-command?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=the-unix-touch-command</link>
		<comments>http://charles.lescampeurs.org/2008/09/11/the-unix-touch-command#comments</comments>
		<pubDate>Thu, 11 Sep 2008 05:30:19 +0000</pubDate>
		<dc:creator>CharlyBr</dc:creator>
				<category><![CDATA[Command line]]></category>
		<category><![CDATA[coretutils]]></category>
		<category><![CDATA[shell]]></category>

		<guid isPermaLink="false">http://charles.lescampeurs.org/?p=53</guid>
		<description><![CDATA[This post is a quick ref on the linux touch command. All the examples have been tested on Linux. This command is used to update the access and modification times of files. touch&#8217;s syntax touch [option] file_name(s) touch file1 file2 file3 Here some examples: # touch /tmp/file # ls -l /tmp/file rw-r--r-- 1 charlybr charlybr [...]]]></description>
			<content:encoded><![CDATA[<p>This post is a quick ref on the linux touch command. All the examples have been tested on Linux.</p>
<p>This command is used to update the access and modification times of files.</p>
<ul>
<li>touch&#8217;s syntax</li>
</ul>
<pre>touch [option] file_name(s)
touch file1 file2 file3</pre>
<ul>
<li>Here some examples:</li>
</ul>
<pre># touch /tmp/file
# ls -l /tmp/file
rw-r--r-- 1 charlybr charlybr 0 Sep 10 16:13 /tmp/file</pre>
<ul>
<li>Update access and modification time to current time:</li>
</ul>
<pre># ls -l /tmp/file
rw-r--r-- 1 charlybr charlybr 0 Sep 10 16:13 /tmp/file
# touch /tmp/file
# ls -l /tmp/file
rw-r--r-- 1 charlybr charlybr 0 Sep 10 16:14 /tmp/file</pre>
<ul>
<li>Update access and modification time to a specified timestamp ([[CC]YY]MMDDhhmm[.ss] format):</li>
</ul>
<pre># touch -t 09091842 /tmp/file
# ls -l /tmp/file
-rw-r--r-- 1 charlybr charlybr 0 Sep  9 18:42 /tmp/file</pre>
<ul>
<li>Update access and modification time to a specified date</li>
</ul>
<pre># touch -d '9 Sep' /tmp/file
# ls -l /tmp/file
-rw-r--r-- 1 charlybr charlybr 0 Sep  9 00:00 /tmp/file
# touch -d '9 Sep 2008 13:14' /tmp/file
# ls -l /tmp/file
-rw-r--r-- 1 charlybr charlybr 0 Sep  9 13:14 /tmp/file</pre>
<h2>Links</h2>
<ul>
<li>touch is part of the <a title="Coreutils package" href="http://www.gnu.org/software/coreutils/" target="_blank">Coreutils</a> package</li>
<li><a title="touch documentation page" href="http://www.gnu.org/software/coreutils/manual/html_node/touch-invocation.html#touch-invocation" target="_blank">touch documentation page</a></li>
<li><a title="touch man page on FreeBSD" href="http://www.freebsd.org/cgi/man.cgi?query=touch&amp;apropos=0&amp;sektion=0&amp;manpath=FreeBSD+7.0-RELEASE&amp;format=html" target="_blank">man page on FreeBSD</a></li>
</ul>
 <img src="http://charles.lescampeurs.org/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?view=1&post_id=53" width="1" height="1" style="display: none;" />]]></content:encoded>
			<wfw:commentRss>http://charles.lescampeurs.org/2008/09/11/the-unix-touch-command/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Retrieve file from svn</title>
		<link>http://charles.lescampeurs.org/2008/05/23/retrieve-file-from-svn?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=retrieve-file-from-svn</link>
		<comments>http://charles.lescampeurs.org/2008/05/23/retrieve-file-from-svn#comments</comments>
		<pubDate>Fri, 23 May 2008 05:51:31 +0000</pubDate>
		<dc:creator>CharlyBr</dc:creator>
				<category><![CDATA[Command line]]></category>
		<category><![CDATA[svn]]></category>

		<guid isPermaLink="false">http://charles.lescampeurs.org/?p=17</guid>
		<description><![CDATA[Sometimes you need to retrieve a single file from SVN without doing a checkout on the repository. SVN provides the svn cat to output the content of a file. You can redirect the output to get the file as : svn cat https://svn.mydomain.com/project/folder/file.ext &#62; file.ext You can also use a simple shell script to do [...]]]></description>
			<content:encoded><![CDATA[<p>Sometimes you need to retrieve a single file from SVN without doing a checkout on the repository.</p>
<p>SVN provides the <a title="svn cat command" href="http://svnbook.red-bean.com/en/1.4/svn.ref.svn.c.cat.html" target="_blank">svn cat</a> to output the content of a file. You can redirect the output to get the file as :</p>
<pre>svn cat https://svn.mydomain.com/project/folder/file.ext &gt; file.ext</pre>
<p>You can also use a simple shell script to do the work :</p>
<pre>$ cat svnget</pre>
<pre>#!/bin/sh

if [ -z "$1" ]; then
        echo
        echo "Usage : $0 &lt;SVN-URL&gt;"
        echo
        exit
fi

fn=`basename $1`
svn cat $1 &gt; $fn</pre>
 <img src="http://charles.lescampeurs.org/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?view=1&post_id=17" width="1" height="1" style="display: none;" />]]></content:encoded>
			<wfw:commentRss>http://charles.lescampeurs.org/2008/05/23/retrieve-file-from-svn/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Automatically set title on iTerm tabs</title>
		<link>http://charles.lescampeurs.org/2008/05/07/automatically-set-title-on-iterm-tabs?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=automatically-set-title-on-iterm-tabs</link>
		<comments>http://charles.lescampeurs.org/2008/05/07/automatically-set-title-on-iterm-tabs#comments</comments>
		<pubDate>Wed, 07 May 2008 12:10:53 +0000</pubDate>
		<dc:creator>CharlyBr</dc:creator>
				<category><![CDATA[Command line]]></category>
		<category><![CDATA[bash]]></category>
		<category><![CDATA[iTerm]]></category>

		<guid isPermaLink="false">http://charles.lescampeurs.org/?p=11</guid>
		<description><![CDATA[If like me you use iTerm for your terminal sessions, this is the tips to dynamically set the tab title. As I&#8217;m using the bash shell, the tab title can be automatically set with the PROMPT_COMMAND variable. You can set this variable in /etc/profile or in your .bashrc Mine is like this : export PROMPT_COMMAND=&#8217;echo [...]]]></description>
			<content:encoded><![CDATA[<p style="text-align: center;"><a href="http://charles.lescampeurs.org/wp-content/uploads/2008/05/picture-1.png"><img class="size-full wp-image-12" title="iTerm tabs title" src="http://charles.lescampeurs.org/wp-content/uploads/2008/05/picture-1.png" alt="" width="361" height="135" /></a></p>
<p>If like me you use <a title="iTerm.app" href="http://iterm.sourceforge.net/" target="_blank">iTerm</a> for your terminal sessions, this is the tips to dynamically set the tab title.</p>
<p>As I&#8217;m using the bash shell, the tab title can be automatically set with the <tt>PROMPT_COMMAND</tt> variable. You can set this variable in <tt>/etc/profile</tt> or in your <tt>.bashrc</tt></p>
<p>Mine is like this :</p>
<p>export PROMPT_COMMAND=&#8217;echo -ne &#8220;\033]0;${USER}@${HOSTNAME%%.*}\007&#8243;&#8216;</p>
<p>The content of the variable is executed each time bash prints your prompt. Here echo is executed with the escape sequence to set the term title.</p>
<h2>More informations</h2>
<p>Some readings about this subject :</p>
<ul>
<li><a href="http://xanana.ucsc.edu/xtal/iterm_tab_customization.html" target="_blank">iTerm Shell Customizations for bash, zsh and tcsh</a></li>
<li><a href="http://www.faqs.org/docs/Linux-HOWTO/Bash-Prompt-HOWTO.html" target="_blank">an old Bash prompt HOWTO</a></li>
<li><a href="http://www.gnu.org/software/bash/" target="_blank">Bash Homepage</a></li>
</ul>
 <img src="http://charles.lescampeurs.org/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?view=1&post_id=11" width="1" height="1" style="display: none;" />]]></content:encoded>
			<wfw:commentRss>http://charles.lescampeurs.org/2008/05/07/automatically-set-title-on-iterm-tabs/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Command line history</title>
		<link>http://charles.lescampeurs.org/2008/05/02/command-line-history?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=command-line-history</link>
		<comments>http://charles.lescampeurs.org/2008/05/02/command-line-history#comments</comments>
		<pubDate>Fri, 02 May 2008 15:54:28 +0000</pubDate>
		<dc:creator>CharlyBr</dc:creator>
				<category><![CDATA[Command line]]></category>
		<category><![CDATA[history]]></category>

		<guid isPermaLink="false">http://charles.lescampeurs.org/?p=3</guid>
		<description><![CDATA[As read here, this is my command line history on my MacBook : [cc lang="bash" line_numbers="false"]$ history 1000 &#124; awk &#8216;{a[$2]++}END{for(i in a){print a[i] &#8221; &#8221; i}}&#8217; &#124; sort -rn &#124; head[/cc] [cc lang="bash" line_numbers="false"] 240 ssh 62 cd 55 scp 33 for 28 vim 25 ping 17 history 13 ls 4 sudo 3 telnet [...]]]></description>
			<content:encoded><![CDATA[<p>As read <a href="http://blog.kovyrin.net/2008/04/28/command-line-history/" target="_blank">here</a>, this is my command line history on my MacBook :</p>
<p>[cc lang="bash" line_numbers="false"]$ history 1000 | awk &#8216;{a[$2]++}END{for(i in a){print a[i] &#8221; &#8221; i}}&#8217; | sort -rn | head[/cc]</p>
<p><tt>[cc lang="bash" </tt>line_numbers="false"<tt>]<br />
240 ssh<br />
62 cd<br />
55 scp<br />
33 for<br />
28 vim<br />
25 ping<br />
17 history<br />
13 ls<br />
4 sudo<br />
3 telnet<br />
[/cc]</tt></p>
 <img src="http://charles.lescampeurs.org/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?view=1&post_id=3" width="1" height="1" style="display: none;" />]]></content:encoded>
			<wfw:commentRss>http://charles.lescampeurs.org/2008/05/02/command-line-history/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

