<?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>WiredRevolution.com &#187; find</title>
	<atom:link href="http://www.wiredrevolution.com/tag/find/feed" rel="self" type="application/rss+xml" />
	<link>http://www.wiredrevolution.com</link>
	<description>A Bit of Linux Wisdom</description>
	<lastBuildDate>Wed, 18 Jan 2012 22:45:50 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3</generator>
		<item>
		<title>Find the exit status of a previous command in Bash</title>
		<link>http://www.wiredrevolution.com/bash-programming/find-the-exit-status-of-a-previous-command-in-bash?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=find-the-exit-status-of-a-previous-command-in-bash</link>
		<comments>http://www.wiredrevolution.com/bash-programming/find-the-exit-status-of-a-previous-command-in-bash#comments</comments>
		<pubDate>Fri, 14 Jan 2011 17:30:01 +0000</pubDate>
		<dc:creator>Ryan</dc:creator>
				<category><![CDATA[bash]]></category>
		<category><![CDATA[$?]]></category>
		<category><![CDATA[access]]></category>
		<category><![CDATA[command]]></category>
		<category><![CDATA[find]]></category>
		<category><![CDATA[print]]></category>
		<category><![CDATA[return]]></category>
		<category><![CDATA[return code]]></category>
		<category><![CDATA[return statis]]></category>
		<category><![CDATA[return value]]></category>
		<category><![CDATA[script]]></category>
		<category><![CDATA[shell]]></category>
		<category><![CDATA[statis]]></category>
		<category><![CDATA[variable]]></category>

		<guid isPermaLink="false">http://www.wiredrevolution.com/?p=1464</guid>
		<description><![CDATA[<img src="http://www.wiredrevolution.com/wp-content/uploads/bash_icon.png" width="80" height="34" alt="" title="bash" /><br/>Most programs will return an exit status of 0 if the program was successful, while a non-zero exit status usually indicates an error. You can find the exit status or exit code of the previously executed command by accessing the &#8220;$?&#8221; shell variable. $ COMMAND $ echo $? Typically when a command terminates on a [...]


Related posts<ol><li><a href='http://www.wiredrevolution.com/bash-programming/find-the-pid-of-a-background-child-process-in-bash' rel='bookmark' title='Permanent Link: Find the PID of a background child process in Bash'>Find the PID of a background child process in Bash</a></li>
<li><a href='http://www.wiredrevolution.com/bash-programming/find-the-pid-of-the-current-bash-script' rel='bookmark' title='Permanent Link: Find the PID of the current Bash script'>Find the PID of the current Bash script</a></li>
<li><a href='http://www.wiredrevolution.com/bash-programming/find-the-parent-pid-of-a-bash-script' rel='bookmark' title='Permanent Link: Find the parent PID of a Bash Script'>Find the parent PID of a Bash Script</a></li>
</ol>]]></description>
			<content:encoded><![CDATA[<img src="http://www.wiredrevolution.com/wp-content/uploads/bash_icon.png" width="80" height="34" alt="" title="bash" /><br/><p>Most programs will return an exit status of 0 if the program was successful, while a non-zero exit status usually indicates an error. You can find the exit status or exit code of the previously executed command by accessing the &#8220;<strong>$?</strong>&#8221; shell variable.</p>
<p><code>$ COMMAND<br />
$ echo $?</code></p>
<p>Typically when a command terminates on a fatal signal whose number is N, Bash uses the value 128+N as the exit status. If a command is not found, the child process created to execute it returns a status of 127. If a command is found but is not executable, the return status is 126.</p>
<p>You can also use the exit status in a conditional.</p>
<p><code>#!/bin/bash<br />
COMMAND<br />
STATUS=$?<br />
if [ $STATUS -eq 0 ]; then<br />
   echo "Command Successful"<br />
else<br />
   echo "Command Failed"<br />
fi</code></p>


<p>Related posts<ol><li><a href='http://www.wiredrevolution.com/bash-programming/find-the-pid-of-a-background-child-process-in-bash' rel='bookmark' title='Permanent Link: Find the PID of a background child process in Bash'>Find the PID of a background child process in Bash</a></li>
<li><a href='http://www.wiredrevolution.com/bash-programming/find-the-pid-of-the-current-bash-script' rel='bookmark' title='Permanent Link: Find the PID of the current Bash script'>Find the PID of the current Bash script</a></li>
<li><a href='http://www.wiredrevolution.com/bash-programming/find-the-parent-pid-of-a-bash-script' rel='bookmark' title='Permanent Link: Find the parent PID of a Bash Script'>Find the parent PID of a Bash Script</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://www.wiredrevolution.com/bash-programming/find-the-exit-status-of-a-previous-command-in-bash/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Find the parent PID of a Bash Script</title>
		<link>http://www.wiredrevolution.com/bash-programming/find-the-parent-pid-of-a-bash-script?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=find-the-parent-pid-of-a-bash-script</link>
		<comments>http://www.wiredrevolution.com/bash-programming/find-the-parent-pid-of-a-bash-script#comments</comments>
		<pubDate>Sun, 09 Jan 2011 17:53:03 +0000</pubDate>
		<dc:creator>Ryan</dc:creator>
				<category><![CDATA[bash]]></category>
		<category><![CDATA[$PPID]]></category>
		<category><![CDATA[access]]></category>
		<category><![CDATA[child]]></category>
		<category><![CDATA[find]]></category>
		<category><![CDATA[parent]]></category>
		<category><![CDATA[PID]]></category>
		<category><![CDATA[print]]></category>
		<category><![CDATA[process]]></category>
		<category><![CDATA[process ID]]></category>
		<category><![CDATA[script]]></category>
		<category><![CDATA[shell]]></category>
		<category><![CDATA[variable]]></category>

		<guid isPermaLink="false">http://www.wiredrevolution.com/?p=1449</guid>
		<description><![CDATA[<img src="http://www.wiredrevolution.com/wp-content/uploads/bash_icon.png" width="80" height="34" alt="" title="bash" /><br/>For any number of reasons you may want to know the parent process ID of the current Bash script. You can find the parent process of the current Bash script or shell by printing the &#8216;$PPID&#8216; shell variable. $ echo $PPID20341 Related postsFind the PID of the current Bash script Find the PID of a [...]


Related posts<ol><li><a href='http://www.wiredrevolution.com/bash-programming/find-the-pid-of-the-current-bash-script' rel='bookmark' title='Permanent Link: Find the PID of the current Bash script'>Find the PID of the current Bash script</a></li>
<li><a href='http://www.wiredrevolution.com/bash-programming/find-the-pid-of-a-background-child-process-in-bash' rel='bookmark' title='Permanent Link: Find the PID of a background child process in Bash'>Find the PID of a background child process in Bash</a></li>
<li><a href='http://www.wiredrevolution.com/bash-programming/find-the-exit-status-of-a-previous-command-in-bash' rel='bookmark' title='Permanent Link: Find the exit status of a previous command in Bash'>Find the exit status of a previous command in Bash</a></li>
</ol>]]></description>
			<content:encoded><![CDATA[<img src="http://www.wiredrevolution.com/wp-content/uploads/bash_icon.png" width="80" height="34" alt="" title="bash" /><br/><p>For any number of reasons you may want to know the parent process ID of the current Bash script. You can find the parent process of the current Bash script or shell by printing the &#8216;<strong>$PPID</strong>&#8216; shell variable.</p>
<p><code>$ echo $PPID</code><code>20341</code></p>


<p>Related posts<ol><li><a href='http://www.wiredrevolution.com/bash-programming/find-the-pid-of-the-current-bash-script' rel='bookmark' title='Permanent Link: Find the PID of the current Bash script'>Find the PID of the current Bash script</a></li>
<li><a href='http://www.wiredrevolution.com/bash-programming/find-the-pid-of-a-background-child-process-in-bash' rel='bookmark' title='Permanent Link: Find the PID of a background child process in Bash'>Find the PID of a background child process in Bash</a></li>
<li><a href='http://www.wiredrevolution.com/bash-programming/find-the-exit-status-of-a-previous-command-in-bash' rel='bookmark' title='Permanent Link: Find the exit status of a previous command in Bash'>Find the exit status of a previous command in Bash</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://www.wiredrevolution.com/bash-programming/find-the-parent-pid-of-a-bash-script/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Find the PID of the current Bash script</title>
		<link>http://www.wiredrevolution.com/bash-programming/find-the-pid-of-the-current-bash-script?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=find-the-pid-of-the-current-bash-script</link>
		<comments>http://www.wiredrevolution.com/bash-programming/find-the-pid-of-the-current-bash-script#comments</comments>
		<pubDate>Sun, 09 Jan 2011 17:18:51 +0000</pubDate>
		<dc:creator>Ryan</dc:creator>
				<category><![CDATA[bash]]></category>
		<category><![CDATA[$$]]></category>
		<category><![CDATA[access]]></category>
		<category><![CDATA[current]]></category>
		<category><![CDATA[environment variable]]></category>
		<category><![CDATA[find]]></category>
		<category><![CDATA[PID]]></category>
		<category><![CDATA[print]]></category>
		<category><![CDATA[process ID]]></category>
		<category><![CDATA[script]]></category>
		<category><![CDATA[shell]]></category>
		<category><![CDATA[variable]]></category>

		<guid isPermaLink="false">http://www.wiredrevolution.com/?p=1438</guid>
		<description><![CDATA[<img src="http://www.wiredrevolution.com/wp-content/uploads/bash_icon.png" width="80" height="34" alt="" title="bash" /><br/>In many cases you will need to determine the PID of a current Bash script or shell. Bash stores a specific variable that allows you to view the process ID of the current shell &#8220;$$&#8216;. You can echo the $$ to print the current PID. $ echo $$23490 Related postsFind the parent PID of a [...]


Related posts<ol><li><a href='http://www.wiredrevolution.com/bash-programming/find-the-parent-pid-of-a-bash-script' rel='bookmark' title='Permanent Link: Find the parent PID of a Bash Script'>Find the parent PID of a Bash Script</a></li>
<li><a href='http://www.wiredrevolution.com/bash-programming/find-the-pid-of-a-background-child-process-in-bash' rel='bookmark' title='Permanent Link: Find the PID of a background child process in Bash'>Find the PID of a background child process in Bash</a></li>
<li><a href='http://www.wiredrevolution.com/bash-programming/find-the-exit-status-of-a-previous-command-in-bash' rel='bookmark' title='Permanent Link: Find the exit status of a previous command in Bash'>Find the exit status of a previous command in Bash</a></li>
</ol>]]></description>
			<content:encoded><![CDATA[<img src="http://www.wiredrevolution.com/wp-content/uploads/bash_icon.png" width="80" height="34" alt="" title="bash" /><br/><p>In many cases you will need to determine the PID of a current Bash script or shell. Bash stores a specific variable that allows you to view the process ID of the current shell &#8220;<strong>$$</strong>&#8216;.</p>
<p>You can echo the $$ to print the current PID.<br />
<code>$ echo $$</code><code>23490</code></p>


<p>Related posts<ol><li><a href='http://www.wiredrevolution.com/bash-programming/find-the-parent-pid-of-a-bash-script' rel='bookmark' title='Permanent Link: Find the parent PID of a Bash Script'>Find the parent PID of a Bash Script</a></li>
<li><a href='http://www.wiredrevolution.com/bash-programming/find-the-pid-of-a-background-child-process-in-bash' rel='bookmark' title='Permanent Link: Find the PID of a background child process in Bash'>Find the PID of a background child process in Bash</a></li>
<li><a href='http://www.wiredrevolution.com/bash-programming/find-the-exit-status-of-a-previous-command-in-bash' rel='bookmark' title='Permanent Link: Find the exit status of a previous command in Bash'>Find the exit status of a previous command in Bash</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://www.wiredrevolution.com/bash-programming/find-the-pid-of-the-current-bash-script/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Have a Bash script determine it&#8217;s own location</title>
		<link>http://www.wiredrevolution.com/bash-programming/have-a-bash-script-determine-its-own-location?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=have-a-bash-script-determine-its-own-location</link>
		<comments>http://www.wiredrevolution.com/bash-programming/have-a-bash-script-determine-its-own-location#comments</comments>
		<pubDate>Wed, 15 Dec 2010 18:49:37 +0000</pubDate>
		<dc:creator>Ryan</dc:creator>
				<category><![CDATA[bash]]></category>
		<category><![CDATA[absolute]]></category>
		<category><![CDATA[BASH]]></category>
		<category><![CDATA[canonicalized]]></category>
		<category><![CDATA[determine]]></category>
		<category><![CDATA[directory]]></category>
		<category><![CDATA[dirname]]></category>
		<category><![CDATA[find]]></category>
		<category><![CDATA[locate]]></category>
		<category><![CDATA[location]]></category>
		<category><![CDATA[path]]></category>
		<category><![CDATA[pathname]]></category>
		<category><![CDATA[pwd]]></category>
		<category><![CDATA[readlink]]></category>
		<category><![CDATA[relative]]></category>
		<category><![CDATA[script]]></category>

		<guid isPermaLink="false">http://www.wiredrevolution.com/?p=1333</guid>
		<description><![CDATA[<img src="http://www.wiredrevolution.com/wp-content/uploads/bash_icon.png" width="80" height="34" alt="" title="bash" /><br/>At some point it may be helpful to have a BASH script dynamically determine the location of itself when executed from anywhere on the system. The following code will produce the canonicalized absolute pathname of the script, as well as the directory that it resides in. The script first determines if the the first argument [...]


Related posts<ol><li><a href='http://www.wiredrevolution.com/bash-programming/convert-a-relative-path-to-absolute-path-in-bash' rel='bookmark' title='Permanent Link: Convert a relative path to absolute path in BASH'>Convert a relative path to absolute path in BASH</a></li>
<li><a href='http://www.wiredrevolution.com/bash-programming/find-the-pid-of-the-current-bash-script' rel='bookmark' title='Permanent Link: Find the PID of the current Bash script'>Find the PID of the current Bash script</a></li>
<li><a href='http://www.wiredrevolution.com/bash-programming/find-the-parent-pid-of-a-bash-script' rel='bookmark' title='Permanent Link: Find the parent PID of a Bash Script'>Find the parent PID of a Bash Script</a></li>
</ol>]]></description>
			<content:encoded><![CDATA[<img src="http://www.wiredrevolution.com/wp-content/uploads/bash_icon.png" width="80" height="34" alt="" title="bash" /><br/><p>At some point it may be helpful to have a BASH script dynamically determine the location of itself when executed from anywhere on the system. The following code will produce the canonicalized absolute pathname of the script, as well as the directory that it resides in.</p>
<p>The script first determines if the the first argument which is a path to the script is a relative or absolute path.  If it is a relative path it will prepend the current working directory. Finally the entire path is canonicalized which resolves all symlinks and removes the extra &#8220;./&#8221;, &#8220;../&#8221; and &#8216;/&#8217; characters.</p>
<p>Here is the script:</p>
<p><code>if [[ "$0" =~ ^/ ]]<br />
then<br />
SCRIPT_LOCATION=$(readlink -f "$0")<br />
else<br />
SCRIPT_LOCATION=$(readlink -f "$(pwd)/""$0")<br />
fi<br />
SCRIPT_DIR=$(dirname $SCRIPT_LOCATION)<br />
echo $SCRIPT_LOCATION<br />
echo $SCRIPT_DIR</code></p>
<p>Now for a quick test. Lets assume our script is located here:<br />
<strong>/home/ryan/scripts/mylocation.sh</strong></p>
<p>Executing the script in the same directory:<br />
<code>$ ./mylocation</code><code>/home/ryan/scripts/mylocation.sh<br />
/home/ryan/scripts</code></p>
<p>Executing in another directory with the absolute path produces the same results:<br />
<code>$ /home/ryan//////scripts/../scripts/mylocation.sh</code><code>/home/ryan/scripts/mylocation.sh<br />
/home/ryan/scripts</code></p>


<p>Related posts<ol><li><a href='http://www.wiredrevolution.com/bash-programming/convert-a-relative-path-to-absolute-path-in-bash' rel='bookmark' title='Permanent Link: Convert a relative path to absolute path in BASH'>Convert a relative path to absolute path in BASH</a></li>
<li><a href='http://www.wiredrevolution.com/bash-programming/find-the-pid-of-the-current-bash-script' rel='bookmark' title='Permanent Link: Find the PID of the current Bash script'>Find the PID of the current Bash script</a></li>
<li><a href='http://www.wiredrevolution.com/bash-programming/find-the-parent-pid-of-a-bash-script' rel='bookmark' title='Permanent Link: Find the parent PID of a Bash Script'>Find the parent PID of a Bash Script</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://www.wiredrevolution.com/bash-programming/have-a-bash-script-determine-its-own-location/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Skip network filesystems when searching with find</title>
		<link>http://www.wiredrevolution.com/system-administration/skip-network-filesystems-when-searching-with-find?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=skip-network-filesystems-when-searching-with-find</link>
		<comments>http://www.wiredrevolution.com/system-administration/skip-network-filesystems-when-searching-with-find#comments</comments>
		<pubDate>Mon, 19 Jan 2009 16:45:06 +0000</pubDate>
		<dc:creator>Ryan</dc:creator>
				<category><![CDATA[system administration]]></category>
		<category><![CDATA[command]]></category>
		<category><![CDATA[filesystem]]></category>
		<category><![CDATA[find]]></category>
		<category><![CDATA[mount]]></category>
		<category><![CDATA[network filesystem]]></category>
		<category><![CDATA[shared filesystem]]></category>
		<category><![CDATA[xdev]]></category>

		<guid isPermaLink="false">http://www.wiredrevolution.com/?p=932</guid>
		<description><![CDATA[<img src="http://www.wiredrevolution.com/wp-content/uploads/sysadmin_icon.png" width="80" height="94" alt="" title="system administration" /><br/>When you run the find command on the root directory of a system you may want to exclude all network filesystems and confine your search to only your local machine. The benefits of this are obvious as it will save you a great amount of time especially if the mounted filesystem is very large. Luckily [...]


Related posts<ol><li><a href='http://www.wiredrevolution.com/commands/search-for-files-with-the-find-command' rel='bookmark' title='Permanent Link: Search for files with the find command'>Search for files with the find command</a></li>
<li><a href='http://www.wiredrevolution.com/system-administration/disable-ext3-boot-time-check-with-tune2fs' rel='bookmark' title='Permanent Link: Disable ext3 boot-time check with tune2fs'>Disable ext3 boot-time check with tune2fs</a></li>
<li><a href='http://www.wiredrevolution.com/system-administration/share-a-remote-filesystem-over-ssh' rel='bookmark' title='Permanent Link: Share a remote filesystem over SSH'>Share a remote filesystem over SSH</a></li>
</ol>]]></description>
			<content:encoded><![CDATA[<img src="http://www.wiredrevolution.com/wp-content/uploads/sysadmin_icon.png" width="80" height="94" alt="" title="system administration" /><br/><p>When you run the <strong>find</strong> command on the root directory of a system you may want to exclude all network filesystems and confine your search to only your local machine.  The benefits of this are obvious as it will save you a great amount of time especially if the mounted filesystem is very large.</p>
<p>Luckily the find command provides this ability with the &#8216;<strong>-xdev</strong>&#8216; or &#8216;<strong>-mount</strong>&#8216; options.</p>
<p>For example:</p>
<pre>
$ find / -xdev -name myfile.txt
</pre>
<p>This command will recursively search for myfile.txt starting in your root directory and skip all externally mounted filesystems.</p>


<p>Related posts<ol><li><a href='http://www.wiredrevolution.com/commands/search-for-files-with-the-find-command' rel='bookmark' title='Permanent Link: Search for files with the find command'>Search for files with the find command</a></li>
<li><a href='http://www.wiredrevolution.com/system-administration/disable-ext3-boot-time-check-with-tune2fs' rel='bookmark' title='Permanent Link: Disable ext3 boot-time check with tune2fs'>Disable ext3 boot-time check with tune2fs</a></li>
<li><a href='http://www.wiredrevolution.com/system-administration/share-a-remote-filesystem-over-ssh' rel='bookmark' title='Permanent Link: Share a remote filesystem over SSH'>Share a remote filesystem over SSH</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://www.wiredrevolution.com/system-administration/skip-network-filesystems-when-searching-with-find/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Search for files with the find command</title>
		<link>http://www.wiredrevolution.com/commands/search-for-files-with-the-find-command?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=search-for-files-with-the-find-command</link>
		<comments>http://www.wiredrevolution.com/commands/search-for-files-with-the-find-command#comments</comments>
		<pubDate>Mon, 20 Oct 2008 12:46:21 +0000</pubDate>
		<dc:creator>Ryan</dc:creator>
				<category><![CDATA[commands]]></category>
		<category><![CDATA[find]]></category>
		<category><![CDATA[locate]]></category>
		<category><![CDATA[search]]></category>

		<guid isPermaLink="false">http://www.wiredrevolution.com/?p=332</guid>
		<description><![CDATA[<img src="http://www.wiredrevolution.com/wp-content/uploads/commands_icon.png" width="80" height="69" alt="" title="commands" /><br/>The find command allows you to recursively search and locate files on your system based on specific criteria. You can search by name, owner, group, type, permissions, date, as well as many others. The find command uses the following format: find [search_path(s)] [search_criteria] The following is the most basic way to run the find command. [...]


Related posts<ol><li><a href='http://www.wiredrevolution.com/commands/securely-copy-remote-files-with-scp' rel='bookmark' title='Permanent Link: Securely copy remote files with scp'>Securely copy remote files with scp</a></li>
<li><a href='http://www.wiredrevolution.com/commands/using-tar-to-archive-files' rel='bookmark' title='Permanent Link: Using tar to archive files'>Using tar to archive files</a></li>
<li><a href='http://www.wiredrevolution.com/commands/list-all-open-files-with-lsof' rel='bookmark' title='Permanent Link: List all open files with lsof'>List all open files with lsof</a></li>
</ol>]]></description>
			<content:encoded><![CDATA[<img src="http://www.wiredrevolution.com/wp-content/uploads/commands_icon.png" width="80" height="69" alt="" title="commands" /><br/><p>The find command allows you to recursively search and locate files on your system based on specific criteria. You can search by name, owner, group, type, permissions, date, as well as many others.</p>
<p>The find command uses the following format:</p>
<pre>
find [search_path(s)] [search_criteria]
</pre>
<p>The following is the most basic way to run the find command. It will list every file and directory within your current working directory.</p>
<pre>
$ find
</pre>
<p>This produces the same output but you are specifically listing the current directory as the search path.</p>
<pre>
$ find .
</pre>
<p>To search the entire filesystem, specify root as the search path (this could take a long time). </p>
<pre>
$ find /
</pre>
<p>You may want to <a href="http://www.wiredrevolution.com/programming/bash-programming/io-redirection-in-bash">redirect stderr</a> to &#8220;<strong>/dev/null</strong>&#8221; to separate the valid output from the errors you might encounter from searching in directories where you don&#8217;t have the correct permissions.</p>
<pre>
$ find / 2> /dev/null
</pre>
<p>To search for a file with a specific name. This will find all files named &#8220;myfile&#8221; within your home directory.</p>
<pre>
$ find ~/ -name myfile
</pre>
<p>This will find all files with a &#8220;.jpg&#8221; extension in your home directory.  The double quotes are needed so the shell will not expand the wildcards in the search string before it passes it to the find command.</p>
<pre>
$ find ~/ -name "*.jpg"
</pre>
<p>You can limit the depth level of the search as well. Set the value to 1 to search within the specified directory without recursing into any subdirectories.  Raising the value will extend the search into that many directory levels.</p>
<pre>
$ find ~/ -name "*.jpg" -maxdepth 1
</pre>
<p>Search for files by permissions. This will find all files in your home directory that have <strong>rwx</strong> permissions for everyone.</p>
<pre>
$ find ~/ -perm 777
</pre>
<p>Search for executables.</p>
<pre>
$ find ~/ -executable
</pre>
<p>Search for files in your home directory which have been modified in the last twenty-four hours.</p>
<pre>
$ find ~/ -mtime 0
</pre>
<p>Search for files that are owned by the user &#8220;ryan&#8221;.</p>
<pre>
$ find / -user ryan
</pre>
<p>The find command is great for locating files but you can also execute commands on those files that it finds.  To execute commands use the &#8216;<strong>-exec</strong>&#8216; option.  The command below will perform an &#8216;<strong>ls -l</strong>&#8216; on each jpeg file it finds in your home directory.</p>
<pre>
$ find ~/ -name "*.jpg" -exec ls -l {} \;
</pre>
<p>The &#8216;<strong>-ok</strong>&#8216; option is similar to &#8216;<strong>-exec</strong>&#8216; but it will prompt you for confirmation before executing each command. This is helpful when you want to execute a potentially dangerous command such as removing files with <strong>rm</strong> like the example below.</p>
<pre>
$ find ~/ -name "*.jpg" -ok rm {} \;
</pre>
<pre>
< rm ... /home/ryan/pic1.jpg > ? n
< rm ... /home/ryan/pic2.jpg > ? n
< rm ... /home/ryan/pic3.jpg > ? n
</pre>


<p>Related posts<ol><li><a href='http://www.wiredrevolution.com/commands/securely-copy-remote-files-with-scp' rel='bookmark' title='Permanent Link: Securely copy remote files with scp'>Securely copy remote files with scp</a></li>
<li><a href='http://www.wiredrevolution.com/commands/using-tar-to-archive-files' rel='bookmark' title='Permanent Link: Using tar to archive files'>Using tar to archive files</a></li>
<li><a href='http://www.wiredrevolution.com/commands/list-all-open-files-with-lsof' rel='bookmark' title='Permanent Link: List all open files with lsof'>List all open files with lsof</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://www.wiredrevolution.com/commands/search-for-files-with-the-find-command/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

