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.

Locate: A Desktop Search Alternative

February 6, 2009 by Sravan  
Filed under Computers

Every once in a while, there is some file that you know you’ve saved but yet can’t find it. Windows Search comes handy at such times but is very slow. Windows Desktop Search, a new utility that is now being shipped with the Windows OSs and being given as an update works using indexing. I think it was started to beat the competition of Google Desktop Search.

IMHO, both Windows and Google Desktop Search consume too many resources.

e.g. Windows Desktop Search recommends Pentium 1 GHz Processor and 256 MB RAM, 500 MB of free hard disk space,… A process that starts automatically all the time. Note that we don’t search for files on our desktop all the time and mostly have an idea which file sits in which folder. A desktop search is for that occasion where we’ve “lost” some file, now and then.

Cygwin provides the best alternatives: locate and find.

locate coupled with updatedb helps you find any file (even hidden ones and those in temporary cache folders) in your system.

When you run the updatedb ($ updatedb), as the name suggests, it updates its database creating a simple index of all the files that are present in the system, with full paths. The first time you run it, like any other indexing application, it takes a few minutes to index the whole system. From the next time, it barely takes a minute, if you run it periodically, that is. I run updatedb about once every week to keep the index fresh.

After updating the file index, you can start using locate.

$ locate <substring-of-filename>

gives you all the files on your PC which contain the substring in their filenames, within a second. Even the files that accidentally got saved in some obscure temporary folder can be retrieved easily.

There are more options to update and locate files with extra preferences but I never had to use them much. The default usage suffices.

The great thing, apart from the speed of retrieval, is that this is not resource intensive and a dedicated process is not always running on your system for it. Of course, you need Cygwin installed.


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


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