Possible Duplicate:
How to grep a text recursively on BusyBox 1.0?

How can I search for a string in a file recursively in BusyBox 1.0 if find and grep are not available ?

(I want to telnet into the router and find out where the iptables rules are stored.)

BusyBox v1.00 (2011.01.13-12:30+0000) Built-in shell (msh)
Enter 'help' for a list of built-in commands.

# help

Built-in commands:
        . : break cd continue eval exec exit export help login newgrp
        read readonly set shift times trap umask wait [ busybox cat chmod
        cp date dmesg echo expr false ftpget ftpput hostname ifconfig
        init insmod kill killall klogd linuxrc ln logger logread ls mkdir
        mknod mount msh mv ping ps pwd reboot renice rm rmmod route sed
        sendarp sh sysinfo syslogd test tftp top traceroute true tty
        umount vconfig wget

marked as duplicate by Gilles, Ulrich Dangel, Renan, jasonwryan, daisy Sep 7 '12 at 6:00

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

  • What is available? busybox help – ams Aug 13 '12 at 12:30
  • Ugh. Neither find nor grep you are left taking mrb's approach. – dmckee Aug 13 '12 at 22:54
  • 1
    Does help in the busybox shell list all the commands busybox lists with busybox --help? There are a lot of them there, I know. – ams Aug 14 '12 at 9:12

I rolled this script that does a recursive pattern search from the current directory. It uses busybox's sh and sed. Tested with busybox 1.17.1; your mileage may vary on 1.00.

#!/bin/busybox sh

sed="busybox sed"


        cd "$searchdir"
        for file in *
            if [ -d "$file" ]
                # recurse into subdirectory
                search_in "$searchterm" "$file" "$prefix\\/$file"
                # use sed like grep
                $sed -rn '/'"$searchterm"'/s/(.*)/'"$prefix\\/$file"': \1/gp' "$file"


# search for command-line search term, starting in current directory (`.`)
search_in "$1" . "."

Not the answer you're looking for? Browse other questions tagged or ask your own question.