<?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"
	>

<channel>
	<title>Trendics Blog &#187; linux</title>
	<atom:link href="http://blog.trendics.com/category/linux/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.trendics.com</link>
	<description></description>
	<pubDate>Mon, 11 Aug 2008 14:59:25 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.6</generator>
	<language>en</language>
			<item>
		<title>Mass Find and Replace from Linux Shell</title>
		<link>http://blog.trendics.com/linux/mass-find-and-replace-from-linux-shell/</link>
		<comments>http://blog.trendics.com/linux/mass-find-and-replace-from-linux-shell/#comments</comments>
		<pubDate>Wed, 30 Jul 2008 15:24:45 +0000</pubDate>
		<dc:creator>kent</dc:creator>
		
		<category><![CDATA[linux]]></category>

		<guid isPermaLink="false">http://blog.trendics.com/?p=99</guid>
		<description><![CDATA[You can do a find and replace on files from the Linux shell using the find and sed commands.  The first example below shows doing a find and replace only in the current directory while the second example below shows doing a find and replace recursing into subdirectories&#8230;

Replace &#8220;www.trendics.com&#8221; with &#8220;tools.trendics.com&#8221; in all html [...]]]></description>
			<content:encoded><![CDATA[<p>You can do a find and replace on files from the Linux shell using the <code>find</code> and <code>sed</code> commands.  The first example below shows doing a find and replace only in the current directory while the second example below shows doing a find and replace recursing into subdirectories&#8230;</p>
<ol>
<li>Replace &#8220;www.trendics.com&#8221; with &#8220;tools.trendics.com&#8221; in all html files in the current directory&#8230;</li>
<p><code>find . </code><code> -maxdepth 1 </code><code>-name "*.html" -type f -exec sed -i 's/www.trendics.com/tools.trendics.com/' {} \;</code></p>
<li>Replace &#8220;www.trendics.com&#8221; with &#8220;tools.trendics.com&#8221; in all text files and all subdirectories&#8230;</li>
<p><code>find . -name "*.txt" -type f -exec sed -i 's/www.trendics.com/tools.trendics.com/' {} \;</code></ol>
<p>Here is how this works&#8230;</p>
<ul>
<li> The dot after the find command specifies to start in the current directory</li>
<li>The <code>-maxdepth 1</code> specifies to only include the current directory</li>
<li>The <code>-name "*.txt"</code> switch specifies to only find txt files</li>
<li>The <code>-type f</code> specifies to only match files</li>
<li>The <code>-exec xyz {} \;</code> specifies to execute xyz for each file where xyz is a sed command specifying to substitute &#8220;tools.trendics.com&#8221; for &#8220;www.trendics.com&#8221;</li>
</ul>
<p>Refer to the documentation on the <a href="http://linux.die.net/man/1/find">find</a> and <a href="http://linux.die.net/man/1/sed">sed</a> for additional options.</p>
<p>Before you run this on your important files, I&#8217;d recommend backing up your important files and I&#8217;d recommend testing your modified find command in a subdirectory with test files to ensure your find command is working as expected.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.trendics.com/linux/mass-find-and-replace-from-linux-shell/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Four Commands to Analyze Connection Usage under Linux</title>
		<link>http://blog.trendics.com/linux/four-commands-to-analyze-connection-usage-under-linux/</link>
		<comments>http://blog.trendics.com/linux/four-commands-to-analyze-connection-usage-under-linux/#comments</comments>
		<pubDate>Mon, 28 Jul 2008 16:11:28 +0000</pubDate>
		<dc:creator>kent</dc:creator>
		
		<category><![CDATA[linux]]></category>

		<guid isPermaLink="false">http://blog.trendics.com/?p=86</guid>
		<description><![CDATA[Is someone establishing an excessive number of connections to your Linux server? Here are the commands I like to run to analyze connection usage.
First, let&#8217;s just store off the netstat output so we don&#8217;t have to retrieve it repeatedly&#8230;
echo "Saving current connections..."
netstat -nta &#62; /tmp/netstat.txt
Next, let&#8217;s see the number of connections per IP address by [...]]]></description>
			<content:encoded><![CDATA[<p>Is someone establishing an excessive number of connections to your Linux server? Here are the commands I like to run to analyze connection usage.</p>
<p>First, let&#8217;s just store off the netstat output so we don&#8217;t have to retrieve it repeatedly&#8230;</p>
<blockquote><p><code>echo "Saving current connections..."<br />
netstat -nta &gt; /tmp/netstat.txt</code></p></blockquote>
<p>Next, let&#8217;s see the number of connections per IP address by extracting the IP address from the netstat output, counting the number of times each IP address was listed in the netstat output, and printing the top 10 (adjust <code>head -10</code> appropriately if you&#8217;d like to see more than the top 10)&#8230;</p>
<blockquote><p><code>echo "Number of connections per IP..."<br />
cut -b 49-75 /tmp/netstat.txt | grep -o -P "\b\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}\b" | sort | uniq -c | sort -n -r -k 1,7 | head -10</code></p></blockquote>
<p>If there is an excessive number of connections from a single IP, you may want to take action to block this IP.</p>
<p>Next, let&#8217;s see the number of connections in different states by extracting the state from the netstat output, and counting the number of times each state was listed in the netstat output&#8230;</p>
<blockquote><p><code>echo "States of connections..."<br />
cut -b 77-90 /tmp/netstat.txt | sort | uniq -c</code></p></blockquote>
<p>The key reason to run this is to understand if you might be under a syn-flood attack. If you see an excessive number of connections in the SYN_RECV state, you may be under a syn-flood attack. It is normally unusual to see a high percentage of connections in a SYN_RECV state.</p>
<p>Next, let&#8217;s see the IP addresses generating connections currently in the SYN_RECV state by grepping the netstat output appropriately, counting the number of times each IP address was listed in the netstat output, and printing the top 10 (adjust <code>head -10</code> appropriately if you&#8217;d like to see more than the top 10)&#8230;</p>
<blockquote><p><code>echo "Number of SYN_RECV connections per IP..."<br />
fgrep "SYN_RECV" /tmp/netstat.txt | cut -b 49-75 | cut -d ':' -f1 | sort | uniq -c | sort -n -r -k 1,7 | head -10</code></p></blockquote>
<p>If the above command does not return any output, you simply do not have any connections in the SYN_RECV state which is good.</p>
<p>With all the above commands, we&#8217;ve analyzed the current connections to the server; however, this is not enough as you may not see IP addresses establishing lots of short connections. To analyze the number of <strong>new</strong> connections established to your server, you can execute this&#8230;</p>
<blockquote><p><code>echo "Count number of new connection requests over the next 100 packets..."<br />
time tcpdump -ns 200 -c 100 &#039;(dst port http or dst port https) and tcp[13] &amp; 2!=0&#039; | grep -o -P &#039;\b\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}.\d{1,5}\s\>&#039; | cut -d &#039;.&#039; -f 1-4 | sort | uniq -c | sort -n -r -k 1,7 | head -25</code></p></blockquote>
<p>For this command, the -c parameter specified how many packets to analyze. Generally, I like to have this command run for about 30 seconds and I adjust the -c parameter to make it run over 30 seconds (very busy servers will need a much larger -c value and very light servers will need a much smaller -c value).</p>
<p>If the above command doesn&#8217;t ever return data, you have the -c parameter too high &#8212; basically the command blocks until the number of specified packets is received and your server has not yet received that number of packets.</p>
<p>In addition, the command above is only analyzing http/https connections; however, you can change the <code>dst port http or dst port https</code> to check other types of connections (consult the <a href="http://linux.die.net/man/8/tcpdump">tcpdump documentation</a>).</p>
<p>Also, it is useful to run all the commands above under normal conditions so you have a baseline to compare against when something abnormal occurs.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.trendics.com/linux/four-commands-to-analyze-connection-usage-under-linux/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Argument List Too Long Message in Linux</title>
		<link>http://blog.trendics.com/linux/argument-list-too-long-message-in-linux/</link>
		<comments>http://blog.trendics.com/linux/argument-list-too-long-message-in-linux/#comments</comments>
		<pubDate>Fri, 25 Jul 2008 18:30:44 +0000</pubDate>
		<dc:creator>kent</dc:creator>
		
		<category><![CDATA[linux]]></category>

		<category><![CDATA[linux tip howto delete files]]></category>

		<guid isPermaLink="false">http://blog.trendics.com/?p=82</guid>
		<description><![CDATA[So, you&#8217;ve filled up a directory with so many files that executing a rm -f * tells you Argument list too long.  Now what?  You can run this to remove the files in a directory too full to use rm -f *&#8230;
# Don't forget to execute this in the right directory!
cd /the-right-directory
# Let's [...]]]></description>
			<content:encoded><![CDATA[<p>So, you&#8217;ve filled up a directory with so many files that executing a <code>rm -f *</code> tells you <code>Argument list too long</code>.  Now what?  You can run this to remove the files in a directory too full to use <code>rm -f *</code>&#8230;</p>
<blockquote><p><code># Don't forget to execute this in the right directory!<br />
cd /the-right-directory</code></p>
<p><code># Let's preview what will get deleted just to be sure</code><br />
<code>find . -maxdepth 1 -name "*" -type f -exec echo {} \;<br />
</code><br />
<code># OK, let's do this<br />
</code><code>find . -maxdepth 1 -name "*" -type f -exec rm -v {} \;</code></p></blockquote>
<p>What is this last find doing?  The dot after find says to do this in the current directory, the <code>-maxdepth 1</code> parameter says not to recurse into subdirectories, the <code>-name "*"</code> parameter says to match any file, the <code>-type f</code> parameter says to do this only on files, and the <code>-exec xyz \;</code> says to execute xyz for each file where xyz is a <code>rm -v</code> command with <code>{}</code> being the name of the current file.</p>
<p><strong>Important:</strong> This is doing a permanent wildcard delete in a directory.  Double check you understand what you are doing before you execute this command.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.trendics.com/linux/argument-list-too-long-message-in-linux/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Find the Files and Directories Using the Most Disk Space under Linux</title>
		<link>http://blog.trendics.com/linux/find-the-files-and-directories-using-the-most-disk-space-under-linux/</link>
		<comments>http://blog.trendics.com/linux/find-the-files-and-directories-using-the-most-disk-space-under-linux/#comments</comments>
		<pubDate>Fri, 25 Jul 2008 01:26:08 +0000</pubDate>
		<dc:creator>kent</dc:creator>
		
		<category><![CDATA[linux]]></category>

		<category><![CDATA[linux disk space tip]]></category>

		<guid isPermaLink="false">http://blog.trendics.com/?p=78</guid>
		<description><![CDATA[Here are three useful commands to find the files and directories using the most disk space under Linux&#8230;

50 largest files&#8230;
find / -path '/proc' -prune -o -size +1000k -printf '%s   %p\n' &#124; sort -k1 -g -r &#124; head -50
50 largest directories (w/o files in subdirectories)&#8230;
du -kS / &#124; sort -k1 -g -r &#124; fgrep [...]]]></description>
			<content:encoded><![CDATA[<p>Here are three useful commands to find the files and directories using the most disk space under Linux&#8230;</p>
<ol>
<li>50 largest files&#8230;
<p><code>find / -path '/proc' -prune -o -size +1000k -printf '%s   %p\n' | sort -k1 -g -r | head -50</code></li>
<li>50 largest directories (w/o files in subdirectories)&#8230;
<p><code>du -kS / | sort -k1 -g -r | fgrep -v '/proc' | head -50</code></li>
<li>50 largest directories (with files in subdirectories)&#8230;
<p><code>du -k / | sort -k1 -g -r | fgrep -v '/proc' | head -50</code></li>
</ol>
<p>This post is not intended to be a tutorial on the Linux shell and how to use each of the referenced commands; instead, these are snippets I&#8217;ve found useful over the years to analyze disk space.</p>
<p>Here is some of the output from running the first command above on one of our servers&#8230;</p>
<blockquote>
<pre>236272746 /root/sb_opt_2007_09_16.tar.gz
123542817 /opt/sb/sb-ext.zip
116717016 /home/twall/sb-ext.tar.gz
116717016 /home/kjohn/sb-ext.tar.gz
74840792 /home/kjohn/ib-ext.tar.gz
74840708 /home/twall/ib-ext.tar.gz
64638719 /root/jdk-6u3-linux-i586-rpm.bin
56835774 /root/jdk-6u3-linux-i586.rpm
54337152 /usr/lib/locale/locale-archive
48276960 /usr/java/jdk1.6.0_03/jre/lib/rt.jar
48117502 /root/install/jdk-1_5_0_12-linux-i586.rpm
39996663 /usr/java/jdk1.5.0_12/jre/lib/rt.jar
29923467 /root/sb_ext.tar.gz
24114161 /root/sb_cvsroot_2007_09_18.tar.gz
21577776 /usr/lib/libgcj.so.7.0.0
19673088 /var/lib/rpm/Packages
19077102 /root/install/MySQL-server-5.0.45-0.i386.rpm
18874368 /var/lib/mysql/ibdata1
18671152 /usr/java/jdk1.6.0_03/src.zip</pre>
</blockquote>
<p>Note that these commands can take a long time to run and generate a lot of load &#8212; be careful running these on production systems.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.trendics.com/linux/find-the-files-and-directories-using-the-most-disk-space-under-linux/feed/</wfw:commentRss>
		</item>
	</channel>
</rss>
