<?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>wp &#124; anoopdotnet &#187; filesystem</title>
	<atom:link href="http://wp.anoop.net/tag/filesystem/feed/" rel="self" type="application/rss+xml" />
	<link>http://wp.anoop.net</link>
	<description>yet another meaningless wordpress blog</description>
	<lastBuildDate>Mon, 06 Feb 2012 08:47:13 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
<atom:link rel="hub" href="http://pubsubhubbub.appspot.com" />
	<atom:link rel="hub" href="http://superfeedr.com/hubbub" />
			<item>
		<title>is your Linux Fu strong? Harness the power of ‘find’</title>
		<link>http://wp.anoop.net/2009/07/is-your-linux-fu-strong-harness-the-power-of-find/</link>
		<comments>http://wp.anoop.net/2009/07/is-your-linux-fu-strong-harness-the-power-of-find/#comments</comments>
		<pubDate>Fri, 10 Jul 2009 21:26:47 +0000</pubDate>
		<dc:creator>Anoop</dc:creator>
				<category><![CDATA[Technobabble]]></category>
		<category><![CDATA[administration]]></category>
		<category><![CDATA[awk]]></category>
		<category><![CDATA[files]]></category>
		<category><![CDATA[filesystem]]></category>
		<category><![CDATA[find]]></category>
		<category><![CDATA[linkedin]]></category>
		<category><![CDATA[linux]]></category>
		<category><![CDATA[sed]]></category>
		<category><![CDATA[shell]]></category>

		<guid isPermaLink="false">http://wp.anoop.net/?p=43</guid>
		<description><![CDATA[I love find There is no other way to put it. It&#8217;s such a fantastic tool and once you get used to it, you almost never use the sub par &#8220;locate&#8221; utility to find files. Some of my favorite find switches and one liners are listed below. Explanations too. Find all directories in the current [...]]]></description>
			<content:encoded><![CDATA[<p>I love <a href="http://linux.about.com/od/commands/l/blcmdl1_find.htm">find</a></p>
<p>There is no other way to put it. It&#8217;s such a fantastic tool and once you get used to it, you almost never use the sub par &#8220;locate&#8221; utility to find files.</p>
<p>Some of my favorite find switches and one liners are listed below. Explanations too.</p>
<p>Find all directories in the current directory only without going any deeper that start with &#8220;20&#8243;. Note that I have included &#8216;-mindepth 1&#8242; and there is a reason for that. Try excluding it and you&#8217;ll see exactly what I mean.<br />
<code><br />
find ./ -maxdepth 1 -mindepth 1 -type d -name "20*"<br />
</code></p>
<p>Find all files named config.php in this directory and all sub directories. Print the name of the file and run &#8216;ls -al&#8217; on the file. run a grep command for &#8220;string1&#8243; (case insensitive) against the files. I find this command very useful in doing a single replacement across many files. It helps me determine what will change if I run a mass replacement. The &#8220;{}&#8221; at the end is the name of the file that is replaced in the command. Without that, you will get an error.<br />
<code><br />
find ./ -name "config.php" -ls -print -exec grep -i string1 {} \;<br />
</code></p>
<p>Now I can find those same files and then run a sed command that will replace all occurrences of string1 with string2. The &#8220;-i&#8221; in this case tells sed to make the change to the file in place without creating a new file. This way you have less to clean up but be careful because there is no backup. If you want to backup the file, use &#8220;-i&#8221; where  is the extension you want the backup file to have. E.g. -i.bak<br />
<code><br />
find ./ -name "config.php" -exec sed -i "s/string1/string2/g" {} \;</code></p>
<p>Another use of exec where you sub {} for the file name allows you to do cool things like back up many different files with the same condition. In this case, anything that is &#8220;config.*&#8221; will be &#8220;config.*.bak&#8221;.<br />
<code><br />
find ./-name "config.*" - exec cp {} {}.bak \;</code></p>
<p>Find any directories that have a no permissions for group and others. This is important if you want to find directories that don&#8217;t have permissions that are needed for users to enter a directory. After this, you can use -exec chmod 755 {} \; to change the permissions appropriately.<br />
<code><br />
find ./ -type d -perm 0700<br />
</code></p>
<p>Find any files that are owned by a particular user. You can also specify &#8220;-group&#8221; to find files by user and group names. I use this to find files owned by &#8220;root&#8221; in home directories and then chown them to the appropriate user.<br />
<code><br />
find ./ -user "username"<br />
</code></p>
<p>The -exec feature in find is perhaps the most valuable aspect of &#8220;find&#8221;. I use it several times a day in combination with <a href="http://www.gnu.org/software/sed/">sed</a> and <a href="http://www.gnu.org/manual/gawk/gawk.html">awk</a> to do all sorts of one liners that would normally need a script.</p>
<p>Don&#8217;t forget that you can do all sorts of really neat things with find, sed, awk if you use regular expressions.</p>
]]></content:encoded>
			<wfw:commentRss>http://wp.anoop.net/2009/07/is-your-linux-fu-strong-harness-the-power-of-find/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

