grep command not found in adb shell

2020-07-10 07:25发布

问题:

After my phone is connected to the computer through adb, going to adb shell and then typing grep gives me

grep: not found  

Is this a problem with my adb installation or my phone? How do I get grep to work for my device?

PS: This is the reason why I think it might a problem with my phone (as opposed to the adb installation)
https://stackoverflow.com/a/12143669/1693203
The answer says

The grep utility may not be installed on your device.

However, I may have misunderstood the statement. How do I get grep working?

回答1:

grep command is not installed on your device by default. If you need to use grep command in your device, you can cross-compile busybox then invoke grep under busybox.

However if you are in Linux or Cygwin, you can pipe the command output and use the grep in PC to get result you want, e.g.

$ adb shell ps |grep google
app_5     279   71    200212 30928 ffffffff 00000000 S com.google.process.gapps
app_66    481   71    122804 21632 ffffffff 00000000 S com.google.android.apps.maps
app_66    32311 71    120200 20916 ffffffff 00000000 S com.google.android.apps.maps:NetworkLocationService


回答2:

in your case that means:The grep utility may is not be installed on your device.

install busybox from playstore then perform

busybox grep