rgrep: Recursive Grep for the Zaurus

Tired of struggling to figure out where something is on your Zaurus? BusyBox did us the disservice of leaving recursion out of grep in versions 0.52 and 0.60.3, so searching for something can be a painful process unless you know exactly which directory or subdirectory you have put something in.

For those of you who are not used to using the command line, grep is a handy command that is used to locate a file or files containing a keyword or keyword pattern that is supplied by the user. So, it is handy if you want to find a file when you either do not know the filename you gave it, or need to read files on a certain topic. On normal Linux installations, grep can use "recursion" to look all over for files, but the crippled version we have on our zaurii only hunts the files in one specific directory.

But if you use ROM 2.38 or 3.10, and probably any other ROMs which may be missing recursive grep, you are in luck. Kyle Davenport (aka Quickening) has written a recursive grep for the Zaurus using standard kernel commands, written specifically to work with Sharp's quirky modifications of the kernel.

He said rgrep probably works on any ROM that uses standard GNU utilities and can be run on Linux desktops. But it has not been tested on other Zaurus ROMs. If you try it out or modify it for use on another ROM, please let one of us know so that the information here can be updated.

If you are not accustomed to adding software that is not in an ipk, then just take rgrep and move it to a directory that is in your "path". On my Zaurus, I put it in /home/QtPalmtop/bin. You can find out the names of the directories in your path by typing:

echo $PATH

If rgrep does not run even if you put it into your path, then make sure you tell your Zaurus that it is an executable file. Just enter the following command, making sure that the path reflects where you actually put your copy:

chmod 700 /home/QtPalmtop/bin/rgrep

To use rgrep, the syntax is very similar to the syntax for grep. You enter rgrep, followed by the search pattern, followed by the name of the directory you wish to search. If you do not give a directory, the default is to search the entire file system.

rgrep "search pattern" [directory to search]

So, for example, to find a file in my Documents folder, containing the phrase "documents tab" I could enter:

bash-2.05# rgrep "documents tab" Documents Documents/text/plain/mySDcard.txt: accidentally moved a document from /mnt/card to /home/root when viewing the documents tab bash-2.05#

My only challenge with rgrep is that it handles wildcards differently than the GNU version 2.2 grep that is on ROM 2.38. I still get confused about when to surround the file pattern with quotes and when not to use the quote marks, but rgrep does have an added feature of telling the user how many files were parsed if no matches were found. So if your results look suspicious, examine the output carefully, and try either adding or removing quotes around your search pattern or search path.

For example, if you have 300 files with the file pattern, or in the directory to be searched, and rgrep tells you "no files found!" or "no matches found in 2 files", you know you did something wrong.

You can download rgrep from:


As I mentioned above, rgrep primarily uses standard GNU grep options and syntax. The official usage information for the November 2006 version of rgrep is:

usage: rgrep [-a] [-d] -A:B:CcEe:Ff:GHhilnsvwx
[search-pattern] [file-pattern]
==> note: grep options default to -His
use -a to follow all links
use -d to turn on debugging

If the usage notes above are confusing to you, you can simply use the defaults by telling rgrep a search pattern and file pattern, as follows:

Wildcards in File Pattern

Note that, unlike standard grep on many distributions, this version of rgrep requires quotes around the file pattern if you use a wildcard, in order to get the desired results. The following search for the word "search" failed because I failed to surround my file pattern "sdjf*" with quotes. Notice that rgrep detected the problem and that debugging was automatically turned on because of this, in this particular instance:

bash-2.05# rgrep search sdjf*
debugging enabled.
Search for "sdjf-about.html" in "./sdjf-aliases.html" files with "grep -His"...
no matches found in 1 files

Something was obviously wrong with the above output, since I wanted rgrep to search about 50 files. However, when I surrounded my file pattern with quotes, as in the following example, I obtained the desired results:

bash-2.05# rgrep search "sdjf*"
./Documents/text/plain/sdjf_tutorial.html.txt: lost when I first went there, so in case you need the suggestion, I recommend that you post in one of the following two subforums if a search at oesf doesn't turn up anything helpful:
./sdjf-consoleapps.html: opie-embeddedkonsole_1.5.0-6_arm.ipk. You need to research the other links further to make sure they would be compatible with your ROM.
./sdjf-tutorial.html: I got pretty lost when I first went there, so in case you need the suggestion, I recommend that you post in one of the following two subforums if a search at oesf does not turn up anything helpful:
./sdjf-rgrep.html:of leaving recursion out of grep in versions 0.52 and 0.60.3, so searching for./sdjf-rgrep.html:search pattern, followed by the name of the directory
./sdjf-rgrep.html:you wish to search. If you do not give a directory,
./sdjf-rgrep.html:the default is to search the entire file system.

Debugging Mode

Following All Links

Missing "dirname" Command

On some Zauruses, you may get the following cryptic error message from rgrep:

missing dirname - please make link to busybox

If that happens to you, enter the following command to find out where your BusyBox is:

bash-2.05# which busybox

Please note that these instructions were written with Zaurus and other embedded device users in mind. If you have some other version of "dirname" installed, that probably will be okay, you do not have to install BusyBox.

In this example, you can then create a symlink by entering the following, all on one line:

ln -s /bin/busybox /home/QtPalmtop/bin/dirname

Non-Existent Directory Pattern or Name

You may encounter another minor problem if you specify a nonexistent directory pattern or name. The November 2006 version of rgrep does not test for the existence of the specified directory, instead just hanging.

If you want to avoid this problem, go get a copy of the most recent version of rgrep! I do recommend, however, that you keep a copy of the older version you have, since there are some changes in the way it functions that in some specific cases I find work better for me. Just rename your old version "rgrep-old" or "rgrep.bak".

For me, the old version of rgrep just hung, with no visible output when I asked the outdated version to search a non-existent directory called "computer" for all files containing the word "ftp".

bash-2.05# rgrep -lw ftp computer

The more recent versions of rgrep give the following results in those instances where a nonexistent directory pattern is given:

bash-2.05# rgrep -lw ftp computer
no files found!

Then I realized that I had swapped out SD cards yesterday, and that there probably is no "computer" directory on the SD card currently inserted in my Zaurus. The rest of this discussion is a simplified explanation for newbies, of how I checked that using "ls", and has no more information specific to rgrep, so command line pros can stop reading the rest of this page and not miss anything.

When this old version of rgrep hadn't given me any output after I gave it some time to do so, I entered CTRL-C to abort rgrep. Then I checked for the existence of "computer" by running the "ls" command. So, if that happens and you want to make sure the directory exists, just try the following:

bash-2.05# ls computer/
ls: computer/: No such file or directory

Note the slash after "computer". If I had not put the slash at the end, I would have just seen that "computer" is a symlink in my home directory to a directory on my SD card, and it would not tell me if there was a "computer" directory on the currently inserted SD card. I get the same results with "ls -l" as long as "computer" is followed by a slash:

bash-2.05# ls -l computer/
ls: computer/: No such file or directory

Removing the slash, I get different results. "ls computer" tells me there is such an entry "computer" in my home directory:

bash-2.05# ls computer

And the arrows in the "ls -l computer" example below, with no slash, tell me that "computer" is a symlink to a subdirectory in my "Webstuff" directory on my SD cards.

bash-2.05# ls -l computer
lrwxrwxrwx    1 root     root            27 Dec 31  2001 computer -> /mnt/card/Webstuff/computer

Only the "ls" or "ls -l" command entered with a slash at the end of the name of the target directory tells me whether the target directory exists. Adding a slash at the end of "computer" tells "ls" to look for the next level down in the directory tree, and tells me there are no entries in the level below "computer" itself:

bash-2.05# ls computer/
ls: computer/: No such file or directory

Revised October 6, 2011