bash 在 adb shell 中找不到 grep 命令

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/27615220/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-18 12:03:38  来源:igfitidea点击:

grep command not found in adb shell

androidlinuxbashshell

提问by user13267

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

我的手机通过adb连接电脑后,进入adb shell然后打字grep给我

grep: not found  

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

这是我的 adb 安装问题还是我的手机问题?如何让 grep 为我的设备工作?

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

PS:这就是为什么我认为它可能是我的手机有问题的原因(与 adb 安装相反)
https://stackoverflow.com/a/12143669/1693203
答案说

The grep utility may not be installed on your device.

您的设备上可能未安装 grep 实用程序。

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

但是,我可能误解了该声明。我如何让 grep 工作?

回答by alijandro

grepcommand is not installed on your device by default. If you need to use grepcommand in your device, you can cross-compile busyboxthen invoke grepunder busybox.

grep默认情况下,您的设备上未安装命令。如果您需要grep在您的设备中使用命令,您可以交叉编译busybox然后grepbusybox.

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

但是,如果您在Linux或 中Cygwin,则可以通过管道grep传输命令输出并使用in PC 来获得您想要的结果,例如

$ 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

回答by wgitscht

in your case that means:The grep utility mayisnot be installed on your device.

在您的情况下,这意味着:grep 实用程序 可能不是安装在你的设备上。

install busybox from playstorethen perform

Playstore安装 busybox然后执行

busybox grep