Indexing with Glimpse
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.
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:
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).
Now that you have created an index, you can search through it. The easiest way to do this is to simply type:
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.
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.
|Bitcoin on Amazon! Sort of...||Sep 28, 2016|
|Free Today: September Issue of Linux Journal (Retail value: $5.99)||Sep 27, 2016|
|nginx||Sep 27, 2016|
|Epiq Solutions' Sidekiq M.2||Sep 26, 2016|
|Nativ Disc||Sep 23, 2016|
|Android Browser Security--What You Haven't Been Told||Sep 22, 2016|
- Free Today: September Issue of Linux Journal (Retail value: $5.99)
- Android Browser Security--What You Haven't Been Told
- Readers' Choice Awards 2013
- Epiq Solutions' Sidekiq M.2
- The Many Paths to a Solution
- Nativ Disc
- Returning Values from Bash Functions
- Securing the Programmer
- Tech Tip: Really Simple HTTP Server with Python
Pick up any e-commerce web or mobile app today, and you’ll be holding a mashup of interconnected applications and services from a variety of different providers. For instance, when you connect to Amazon’s e-commerce app, cookies, tags and pixels that are monitored by solutions like Exact Target, BazaarVoice, Bing, Shopzilla, Liveramp and Google Tag Manager track every action you take. You’re presented with special offers and coupons based on your viewing and buying patterns. If you find something you want for your birthday, a third party manages your wish list, which you can share through multiple social- media outlets or email to a friend. When you select something to buy, you find yourself presented with similar items as kind suggestions. And when you finally check out, you’re offered the ability to pay with promo codes, gifts cards, PayPal or a variety of credit cards.Get the Guide