Skip to content

Thursday, November 26th, 2009

Google Your PC Using Find

February 13, 2009 by Sravan  
Filed under Computers

find is an elaborate search program with a number of features. Unlike the Google Desktop Search and locate, it doesn’t index anything but processes the request on the fly. Thus it is slower.

find is one of the most useful commands when you also have to search within unknown files and make further operations on the result set. It does a recursive search, looking in all subdirectories.

The first set of arguments is always the paths where the search should initiate. $ find /home /tmp <remaining arguments> would search based on the remaining arguments in /home, /tmp and all their subdirectories. If unspecified, the default path is taken as ‘.’, the current working directory.

To search for a specific filename pattern, –name <regexp> is used as the next argument. $ find /home /tmp –name *.sh returns all .SH files present in /home, /tmp and their subdirectories.

Instead of piping, to perform any operation on each of the results returned, –exec is used. $ find /home /tmp –name *.sh –exec grep todo ‘{}’ \; –print searches for the string todo in the above returned files. grep does the search and ‘{}’ implies that all results need to be processed. The –print prints the final output, the actual lines containing the specified string in the files.

Instead of grep, it could be chmod or chown or any operation that can be done of files. These above options are the most common use cases of find.

There are a number of other options to refine the search like complex expressions with boolean operators, the maximum and minimum depth of subdirectories that need to be traversed, the modification times and permissions on files, the file types, etc. You can read about all these in the manual page.

  • StumbleUpon
  • Digg
  • Facebook
  • Mixx
  • Google
  • TwitThis
  • Reddit
  • Yahoo! Buzz
  • Slashdot
  • E-mail this story to a friend!
  • BallHype
  • YardBarker

Speak Your Mind

Tell us what you're thinking...
and oh, if you want a pic to show with your comment, go get a gravatar!


About Us | Advertise with us | Blog for EveryJoe | Privacy Policy | Terms of Use
Get This Theme | Sitemap


All content is Copyright © 2005-2009 b5media. All rights reserved.