Skip to content
This repository has been archived by the owner on Jul 11, 2022. It is now read-only.

How to use codesearch

Manpreet Singh edited this page Jan 18, 2017 · 8 revisions

How to use codesearch

Copied from https://swtch.com/~rsc/regexp/regexp4.html

Index

The first step is to run cindex with a list of directories or files to include in the index:

cindex /usr/include $HOME/src

By default cindex adds to the existing index, if one exists, so the last command is equivalent to the pair of commands:

cindex /usr/include
cindex $HOME/src

With no arguments, cindex refreshes an existing index, so after running the previous commands,

cindex

will rescan /usr/include and $HOME/src and rewrite the index. Run cindex -help for more details.

The index file contains a list of paths (for reindexing, as described above), a list of indexed files, and then the same posting lists we saw at the beginning of this article, one for each trigram. In practice, this index tends to be around 20% of the size of the files being indexed. For example, indexing the Linux 3.1.3 kernel sources, a total of 420 MB, creates a 77 MB index. Of course, the index is organized so that only a small fraction needs to be read for any particular search.

Search

Once the index has been written, run csearch to search:

csearch REGEXP

The regexp syntax is RE2's, which is to say basically Perl's, but without backreferences. Most common options match grep options.

Getting help

See csearch -h and cindex -h for details on all the options available.

Clone this wiki locally