Indexing with Glimpse

 in
Glimpse, a simple but effective indexing package, can help you find particular mail messages in large mail archives and keep track of files in large directories.

Since nearly my entire livelihood is maintained by exchanging electronic mail, my e-mail archives (not including many messages more than a year old) currently use nearly 100MB of my precious hard drive space—enough that I'm starting to consider buying a separate hard drive just for my personal files. In a desperate, somewhat successful, attempt to keep better track of my e-mail archives, I recently installed exmh, a graphical mail program based on MH (a powerful but complex mail reader) and Tcl/Tk.

One optional program that exmh can use to help manage e-mail is glimpse. From some or all of your mail files, this program builds an index, which exmh uses to quickly search for any word you want to look up. I can now search all my e-mail archives for a long-lost letter in less than a minute.

But this article isn't about exmh, as useful as it is for MH users like me. It's about glimpse, an excellent program in its own right.

Preparing Glimpse

Unlike the well-known grep program, glimpse does not usually take an argument telling which files to search. Instead, by default, glimpse looks in every file which it has indexed. This means that glimpse requires an index to work.

Perhaps the simplest way to use glimpse is to index all your files and search them all when you are looking for something. To do that, you need to create the index with:

glimpseindex $HOME

or:

glimpseindex ~

which will index all your files, keeping the index in your home directory in files whose names start with .glimpse_. These files will usually take up about 2% to 3% of the total space of the of the files in your directory.

If you want to exclude certain files' names from the index, you can add their complete path names or “wildcard” expressions with * and ? characters to the file .glimpse_exclude. All of the .glimpse_* files are documented in the glimpseindex man page.

Since your files probably change from time to time, you will need to update the index occasionally. You can either do this manually, using the same command you used to create the index, or create a “cron job” to do it for you (but scheduling jobs with cron is beyond the scope of this article).

Using Glimpse

Now that you have created an index, you can search through it. The easiest way to do this is to simply type:

glimpse word

Glimpse searches through the default index (the one in your home directory) and returns output similar to grep's with the file name prepended to each matching line.

Perhaps your search doesn't turn up the file you are looking for; the word might be misspelled in the file. If you want to allow a one-letter spelling mistake, you can instead use:

glimpse -1 word

Perhaps your search turns up far too many matches. You can limit the matches to only files with names matching a certain pattern with the -F flag. To search only in files ending in .c, use:

glimpse -F '.c$' word

The argument following -F is a full regular expression, like the search patterns used by grep.

You don't have to index only files in your home directory. The -H option specifies a different directory tree to index. The index files are stored in the specified directory. If you want to index the /usr/doc directory provided with many Linux distributions, log in as root (or another user that can write in the /usr/doc directory) and run:

glimpseindex -H /usr/doc

and then any user able to read the /usr/doc/.glimpse_index file will be able to search those documents with:

glimpse -H /usr/doc word

If your searches aren't fast enough, you can trade disk space for time by running glimpseindex with the -o flag, to indicate an index that takes up 7% to 8% of the space of the files being indexed and increases search speed somewhat, or the -b flag to indicate an index that takes up 20% to 30% extra space and increases search speed more.

If you search all the time, you can speed up your searches by running the glimpseserver program in the background. That is covered in the glimpseserver man page.

What Else?

Glimpse can do more than I can cover here, so if you don't see what you are looking for, try it—or at least read the documentation—before giving up. In particular, glimpse supports the options used by agrep (approximate grep), a popular search program written by the authors of glimpse several years ago. agrep and its man page are included in the glimpse distribution. Its options include boolean searches of different kinds.

Glimpse is also the search engine used in the Harvest system, which “is an integrated set of tools to gather, extract, organize, search, cache, and replicate relevant information across the Internet”, according to the Harvest Web site at harvest.cs.colorado.edu.

______________________

White Paper
Linux Management with Red Hat Satellite: Measuring Business Impact and ROI

Linux has become a key foundation for supporting today's rapidly growing IT environments. Linux is being used to deploy business applications and databases, trading on its reputation as a low-cost operating environment. For many IT organizations, Linux is a mainstay for deploying Web servers and has evolved from handling basic file, print, and utility workloads to running mission-critical applications and databases, physically, virtually, and in the cloud. As Linux grows in importance in terms of value to the business, managing Linux environments to high standards of service quality — availability, security, and performance — becomes an essential requirement for business success.

Learn More

Sponsored by Red Hat

White Paper
Private PaaS for the Agile Enterprise

If you already use virtualized infrastructure, you are well on your way to leveraging the power of the cloud. Virtualization offers the promise of limitless resources, but how do you manage that scalability when your DevOps team doesn’t scale? In today’s hypercompetitive markets, fast results can make a difference between leading the pack vs. obsolescence. Organizations need more benefits from cloud computing than just raw resources. They need agility, flexibility, convenience, ROI, and control.

Stackato private Platform-as-a-Service technology from ActiveState extends your private cloud infrastructure by creating a private PaaS to provide on-demand availability, flexibility, control, and ultimately, faster time-to-market for your enterprise.

Learn More

Sponsored by ActiveState