There is busybox and there are terminal emulators that include grep, but they require root to run. It would be better if they could also run without root but with limited access. I only need to grep (read-only access) files in the user data storage.

Is there a way to do grep text searching on Android without root?

There are many text editors already, but they only support ordinary text searching by jumping to the text position, which is not nearly as convenient as grep, where one gets the desired results in a list at one place.

  • 1
    Which Android version are you using? – Firelord Aug 30 '18 at 15:31
  • 1
    Did you try it via adb? – user108993 Aug 30 '18 at 19:56
  • @Adem I know ADB already, but does ADB work without needing an external computer? – neverMind9 Aug 30 '18 at 20:07
  • @Firelord That phone has Android 7, Nougat. But it would be great to have a solution that is compatible with older Android versions too, such as Jelly Bean. – neverMind9 Aug 30 '18 at 20:08
  • 1
    To my knowledge that won't work. – user108993 Aug 30 '18 at 20:08

You are mixing up two things:

  1. Installing a binary like busybox system wide from within an app (which includes grep)
  2. Running a binary

The default app based installers for busybox require root access to install busybox system-wide. This is true, however this is just because it is an app. Once the binary is installed you don't need root access.

Additionally even without root you can also install a busybox (or whatever) binary on your device:

  1. You need to activate Android Debug Bridge (adb)
  2. Copy the binary onto your phone (if it is not already there): adb push busybox /sdcard/
  3. Copy the binary from the sdcard section (where it can't be executed) to different directory like /data/local or /data/local/tmp: adb shell "cat /sdcard/busybox > /data/local/busybox".
  4. Then make it executable using adb shell chmod 0555 /data/local/busybox

Now you can execute it using its full path from within a terminal app or inside adb shell:

/data/local/busybox grep ....

  • I want to add that chmod is not available in Android versions prior to Lollipop. – Firelord Aug 30 '18 at 15:30
  • There's even at least one Busybox installer not requiring root (Busybox Installer (no root)). Apart from that: Any reason you use cat to copy a file – instead of cp? – Izzy Aug 30 '18 at 15:34
  • @Izzy Plus, the adb shell cat will cat something to the computer, not the phone. – iBug Aug 30 '18 at 16:10
  • @iBug that depends on the redirect – and how you quote it: adb shell "cat foo > /sdcard/bar" will stay on-device. But remove the quotes, and it may complain it misses the /sdcard on your computer :) – Izzy Aug 30 '18 at 16:38
  • 1
    @Izzy I remember having encountered a lot of devices that did not had the cp command. However cat was on each and every device available I ever got my hand on. – Robert Aug 30 '18 at 19:18

If you are using Android Lollipop or above, install Termux, install grep (if not already installed) by typing apt install grep, give Storage permission to Termux from Settings app so that Internal Storage can be accessed. And that's it. Enjoy your grep. You can also install busybox the same way in Termux (it appears to come installed with Termux per user iBug) and use its utilities. Installation and usage doesn't require elevated privileges.

If you are using Android version before Lollipop, Robert's answer suggests a good way but some steps can be eliminated. Simply fetch the Android binary compatible with your processor from here, rename it to busybox and push it into Android using as:

adb push busybox /data/local/tmp/   # don't push it into /sdcard/ as it is both unnecessary and removes executable bit from the binary which you cannot add without having busybox's or toybox'x chmod utility. 

You can now use busybox. You would want to setup an alias or change ENVIRONMENT variable of your shell accordingly to map that file.

Alternatiely, while I have not tried them, some grep based apps are available in Play Store and can be found here.

  • 1
    BusyBox comes installed in Termux by defaulr (upon first launch), and it includes a grep. – iBug Aug 30 '18 at 16:10

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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