<?xml version="1.0" encoding="UTF-8"?>
<!-- generator="wordpress/2.0.5" -->
<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/"
	>

<channel>
	<title>chris clarke</title>
	<link>http://squadlimber.com/chris</link>
	<description>software development that works...or something</description>
	<pubDate>Mon, 07 Apr 2008 23:14:16 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.0.5</generator>
	<language>en</language>
			<item>
		<title>Find which process is listening on a port</title>
		<link>http://squadlimber.com/chris/2007/10/17/find-which-process-is-listening-on-a-port/</link>
		<comments>http://squadlimber.com/chris/2007/10/17/find-which-process-is-listening-on-a-port/#comments</comments>
		<pubDate>Wed, 17 Oct 2007 18:20:04 +0000</pubDate>
		<dc:creator>chris.probably</dc:creator>
		
		<category>Unix</category>

		<guid isPermaLink="false">http://squadlimber.com/chris/2007/10/17/find-which-process-is-listening-on-a-port/</guid>
		<description><![CDATA[To find which process is listening on port 22:

lsof -i:22
&#160;
Find out which port a process is listening on e.g. httpd:

lsof -P -c httpd -a -i
&#160;
Or by PID:

lsof -P -p 267 -a -i
&#160;
lsof can also be used to find the files a process has open.  To look for where httpd writes it&#8217;s log files:

lsof -c [...]]]></description>
			<content:encoded><![CDATA[<p>To find which process is listening on port 22:</p>
<div class="bash" style="margin: 35px; border: 1px dashed #eee; font-family: Arial, Monaco, Verdana, monospace; padding: 1em; color: black; background: #fcfcfc; overflow: auto;"><br />
lsof -i:<span style="color: #cc66cc;">22</span><br />
&nbsp;</div>
<p>Find out which port a process is listening on e.g. httpd:</p>
<div class="bash" style="margin: 35px; border: 1px dashed #eee; font-family: Arial, Monaco, Verdana, monospace; padding: 1em; color: black; background: #fcfcfc; overflow: auto;"><br />
lsof -P -c httpd -a -i<br />
&nbsp;</div>
<p>Or by PID:</p>
<div class="bash" style="margin: 35px; border: 1px dashed #eee; font-family: Arial, Monaco, Verdana, monospace; padding: 1em; color: black; background: #fcfcfc; overflow: auto;"><br />
lsof -P -p <span style="color: #cc66cc;">267</span> -a -i<br />
&nbsp;</div>
<p>lsof can also be used to find the files a process has open.  To look for where httpd writes it&#8217;s log files:</p>
<div class="bash" style="margin: 35px; border: 1px dashed #eee; font-family: Arial, Monaco, Verdana, monospace; padding: 1em; color: black; background: #fcfcfc; overflow: auto;"><br />
lsof -c httpd | grep log<br />
&nbsp;</div>
]]></content:encoded>
			<wfw:commentRss>http://squadlimber.com/chris/2007/10/17/find-which-process-is-listening-on-a-port/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Unix stuff</title>
		<link>http://squadlimber.com/chris/2007/10/17/unix-stuff/</link>
		<comments>http://squadlimber.com/chris/2007/10/17/unix-stuff/#comments</comments>
		<pubDate>Wed, 17 Oct 2007 17:58:26 +0000</pubDate>
		<dc:creator>chris.probably</dc:creator>
		
		<category>Unix</category>

		<guid isPermaLink="false">http://squadlimber.com/chris/2007/10/17/unix-stuff/</guid>
		<description><![CDATA[If you work a lot on slow Solaris boxes, you can speed up finds a little bit:

find . -depth -type f -name '*.monkeys'
&#160;
The depth option looks at the contents of directories before the directory itself and the &#8216;type f&#8217; constricts the find to only look at regular files.  You can speed it up a [...]]]></description>
			<content:encoded><![CDATA[<p>If you work a lot on slow Solaris boxes, you can speed up finds a little bit:</p>
<div class="bash" style="margin: 35px; border: 1px dashed #eee; font-family: Arial, Monaco, Verdana, monospace; padding: 1em; color: black; background: #fcfcfc; overflow: auto;"><br />
find . -depth -<span style="color: #000066;">type</span> f -name <span style="color: #ff0000;">'*.monkeys'</span><br />
&nbsp;</div>
<p>The depth option looks at the contents of directories before the directory itself and the &#8216;type f&#8217; constricts the find to only look at regular files.  You can speed it up a bit more if you have more information about the file e.g. the owner:</p>
<div class="bash" style="margin: 35px; border: 1px dashed #eee; font-family: Arial, Monaco, Verdana, monospace; padding: 1em; color: black; background: #fcfcfc; overflow: auto;"><br />
find . -depth -<span style="color: #000066;">type</span> f -user dev -name <span style="color: #ff0000;">'*.monkeys'</span><br />
&nbsp;</div>
<p>Looking for something inside a file and only want to list the files containing your search:</p>
<div class="bash" style="margin: 35px; border: 1px dashed #eee; font-family: Arial, Monaco, Verdana, monospace; padding: 1em; color: black; background: #fcfcfc; overflow: auto;"><br />
grep -l monkeys *<br />
&nbsp;</div>
<p>Working on a box that doesn&#8217;t have recursive grep:</p>
<div class="bash" style="margin: 35px; border: 1px dashed #eee; font-family: Arial, Monaco, Verdana, monospace; padding: 1em; color: black; background: #fcfcfc; overflow: auto;"><br />
find -X . -depth -<span style="color: #000066;">type</span> f -name <span style="color: #ff0000;">'*'</span> | xargs grep -l monkeys<br />
&nbsp;</div>
<p>The &#8216;-X&#8217; option ignores files that would mess with xargs e.g. filenames with spaces in.</p>
]]></content:encoded>
			<wfw:commentRss>http://squadlimber.com/chris/2007/10/17/unix-stuff/feed/</wfw:commentRss>
		</item>
		<item>
		<title>GNUs Not U 4</title>
		<link>http://squadlimber.com/chris/2007/03/05/gnus-not-u-4/</link>
		<comments>http://squadlimber.com/chris/2007/03/05/gnus-not-u-4/#comments</comments>
		<pubDate>Mon, 05 Mar 2007 22:44:29 +0000</pubDate>
		<dc:creator>chris.probably</dc:creator>
		
		<category>Unix</category>

		<guid isPermaLink="false">http://squadlimber.com/chris/2007/03/05/gnus-not-u-4/</guid>
		<description><![CDATA[Here&#8217;s a puzzler. Minimize the following command which looks for multiple entries of a command in the PATH environment variable:
echo $PATH &#124; awk 'BEGIN { RS=":" } ; { print; }' &#124; xargs -I{} find {} -name ant
You could use which:
which ant
But that will only return one answer.
Could use locate:
locate ant
But that will return things [...]]]></description>
			<content:encoded><![CDATA[<p>Here&#8217;s a puzzler. Minimize the following command which looks for multiple entries of a command in the PATH environment variable:</p>
<p><code>echo $PATH | awk 'BEGIN { RS=":" } ; { print; }' | xargs -I{} find {} -name ant</code></p>
<p>You could use which:</p>
<p><code>which ant</code></p>
<p>But that will only return one answer.</p>
<p>Could use locate:</p>
<p><code>locate ant</code></p>
<p>But that will return things not in the PATH.</p>
<p>Could use whereis:</p>
<p><code>whereis ant</code></p>
<p>But that only looks in a list of standard linux places, the PATH may be unconventional.</p>
]]></content:encoded>
			<wfw:commentRss>http://squadlimber.com/chris/2007/03/05/gnus-not-u-4/feed/</wfw:commentRss>
		</item>
		<item>
		<title>GNUs Not U 3</title>
		<link>http://squadlimber.com/chris/2007/02/17/gnus-not-u-3/</link>
		<comments>http://squadlimber.com/chris/2007/02/17/gnus-not-u-3/#comments</comments>
		<pubDate>Sat, 17 Feb 2007 20:18:00 +0000</pubDate>
		<dc:creator>chris.probably</dc:creator>
		
		<category>Unix</category>

		<guid isPermaLink="false">http://squadlimber.com/chris/2007/02/17/gnus-not-u-3/</guid>
		<description><![CDATA[Stop a command from exiting after you logout:
nohup monkeys.sh
Convert html so it can be displayed on a web page:
cat index.html &#124; perl -pe 's/&#60;/&#38;lt;/g; s/&#62;/&#38;gt;/g'
See the strings in a binary file:
strings /bin/rm
Show line numbers of a file:
nl monkeys.c
See a particular line in a file:
cat buildOutput.txt &#124; nl &#124; awk '$1==5 {print; }'
Concatenate files horizontally:
paste times [...]]]></description>
			<content:encoded><![CDATA[<p>Stop a command from exiting after you logout:</p>
<p><code>nohup monkeys.sh</code></p>
<p>Convert html so it can be displayed on a web page:</p>
<p><code>cat index.html | perl -pe 's/&lt;/&amp;lt;/g; s/&gt;/&amp;gt;/g'</code></p>
<p>See the strings in a binary file:</p>
<p><code>strings /bin/rm</code></p>
<p>Show line numbers of a file:</p>
<p><code>nl monkeys.c</code></p>
<p>See a particular line in a file:</p>
<p><code>cat buildOutput.txt | nl | awk '$1==5 {print; }'</code></p>
<p>Concatenate files horizontally:</p>
<p><code>paste times dates people</code></p>
<p>View and save output at the same time:</p>
<p><code>ls | tee filesInthisDirectory.txt</code></p>
<p>Say yes to everything:</p>
<p><code>yes | rm -i *.txt</code></p>
<p>Send a message to everyone:</p>
<p><code>echo 'all your base are belong to us' | wall</code></p>
<p>See a list of processes every 5 seconds:</p>
<p><code>watch -n5 "ps aux"</code></p>
<p>Sort by the second column of a file:</p>
<p><code>cat file.txt | sort -k2</code></p>
<p>Delete a bunch of files matching a regex:</p>
<p><code>find . -name "*.svn" -exec rm -rf '{}' \; -print</code></p>
<p>Reverse a string:</p>
<p><code>echo "Never odd or even" | rev</code></p>
]]></content:encoded>
			<wfw:commentRss>http://squadlimber.com/chris/2007/02/17/gnus-not-u-3/feed/</wfw:commentRss>
		</item>
		<item>
		<title>GNUs Not U 2</title>
		<link>http://squadlimber.com/chris/2007/01/28/gnus-not-u-2/</link>
		<comments>http://squadlimber.com/chris/2007/01/28/gnus-not-u-2/#comments</comments>
		<pubDate>Sun, 28 Jan 2007 01:16:57 +0000</pubDate>
		<dc:creator>chris.probably</dc:creator>
		
		<category>Unix</category>

		<guid isPermaLink="false">http://squadlimber.com/chris/?p=28</guid>
		<description><![CDATA[Kill a command by name:
ps axc &#124; grep httpd &#124; awk '{ print $1; }' &#124; xargs kill
Look for a command exclude your own grep:
ps auxwww &#124; grep command &#124; grep -v grep
Kill a command based on it&#8217;s arguments:
ps axwww &#124; grep port=8889 &#124; grep -v grep &#124; awk '{ print $1; }' &#124; xargs [...]]]></description>
			<content:encoded><![CDATA[<p>Kill a command by name:</p>
<p><code>ps axc | grep httpd | awk '{ print $1; }' | xargs kill</code></p>
<p>Look for a command exclude your own grep:</p>
<p><code>ps auxwww | grep command | grep -v grep</code></p>
<p>Kill a command based on it&#8217;s arguments:</p>
<p><code>ps axwww | grep port=8889 | grep -v grep | awk '{ print $1; }' | xargs kill</code></p>
<p>Can this be simplified?:</p>
<p><code>ps axc | awk '/httpd/{ print $1 }' | xargs kill</code></p>
<p><code>ps axwww | awk '/port=8889/{ print $1 }' | xargs kill</code></p>
<p>But when using the command above we are trying to kill our own awk command!</p>
<p><code>ps axwww | awk '/port=8889/ &#038;&#038; !/awk/ { print $1 }' | xargs kill</code>
</p>
]]></content:encoded>
			<wfw:commentRss>http://squadlimber.com/chris/2007/01/28/gnus-not-u-2/feed/</wfw:commentRss>
		</item>
		<item>
		<title>GNUs Not U</title>
		<link>http://squadlimber.com/chris/2007/01/24/gnus-not-u/</link>
		<comments>http://squadlimber.com/chris/2007/01/24/gnus-not-u/#comments</comments>
		<pubDate>Wed, 24 Jan 2007 19:56:42 +0000</pubDate>
		<dc:creator>chris.probably</dc:creator>
		
		<category>Unix</category>

		<guid isPermaLink="false">http://squadlimber.com/chris/?p=26</guid>
		<description><![CDATA[Highlight some expression using colour:
grep --color expression file
Go to a dir, execute a command and return to the current directory:
(cd dir &#038;&#038; command)
A stopwatch:
time cat ^D
Download a url at 1 AM:
echo 'wget url' &#124; at 01:00
Do some sums:
echo "monkeys=24; monkeys * 6 / 4" &#124; bc
Convert a string to lowercase:
echo 'TeSt' &#124; tr '[:upper:]' '[:lower:]'
List [...]]]></description>
			<content:encoded><![CDATA[<p>Highlight some expression using colour:</p>
<p><code>grep --color expression file</code></p>
<p>Go to a dir, execute a command and return to the current directory:</p>
<p><code>(cd dir &#038;&#038; command)</code></p>
<p>A stopwatch:</p>
<p><code>time cat ^D</code></p>
<p>Download a url at 1 AM:</p>
<p><code>echo 'wget url' | at 01:00</code></p>
<p>Do some sums:</p>
<p><code>echo "monkeys=24; monkeys * 6 / 4" | bc</code></p>
<p>Convert a string to lowercase:</p>
<p><code>echo 'TeSt' | tr '[:upper:]' '[:lower:]'</code></p>
<p>List files that a process has open:</p>
<p><code>lsof -p 483</code></p>
<p>List processes that have the specified path open:</p>
<p><code>lsof ~</code></p>
<p>Display a webpage (MAC/BSD):</p>
<p><code>wget -qO - http://www.cheese.com > tmp.html &#038;&#038; textutil -stdout -convert txt tmp.html</code></p>
<p>Look for a word case insensitively:</p>
<p><code>cat Names | grep -i demarco</code></p>
<p>Search and replace:</p>
<p><code>cat index.html | sed 's/Google/MSN/g'</code></p>
<p>Print lines 10 to 20:</p>
<p><code>cat index.html | sed -n '10,20p;20q'</code></p>
<p>Time how long it takes to calculate PI to 5000 decimal places:</p>
<p><code>time echo "scale=5000; 4*a(1)" | bc -l</code></p>
<p>Convert binary to decimal:</p>
<p><code>echo "obase=10; ibase=2; 01111111" | bc</code></p>
<p>Perform a calculation on some output:</p>
<p><code>ls -al *.html | awk '{sum+=$5} END{print sum}'</code></p>
<p>Fix typos in files but backup the original files:</p>
<p><code>perl -p -i.old -e 's/oldstring/newstring/g' *.txt</code></p>
<p>Execute a command on several computers:</p>
<p><code>perl -e 'for("B","C","D"){`scp command.pl $_:`; `ssh $_ command.pl`; }'</code></p>
<p>Look for a regular expression:</p>
<p><code>cat index.html | perl -ne 'print if /font-size:\s*\d+px/'</code></p>
<p>Print selected lines of a file:</p>
<p><code>cat buildOutput.txt | perl -ne 'print if 1..2'</code></p>
<p>Can you think of another way to print selected lines?</p>
<p>Comma-delimit:</p>
<p><code>ls -l | perl -wne 'BEGIN{$" = ","} @fields = split/\s+/; print "@fields\n";'</code></p>
<p>Find a file without the &#8220;permission denied&#8221; messages:</p>
<p><code>find . -name 'monkeys.txt' 2> /dev/null</code>
</p>
]]></content:encoded>
			<wfw:commentRss>http://squadlimber.com/chris/2007/01/24/gnus-not-u/feed/</wfw:commentRss>
		</item>
	</channel>
</rss>
