我可以在 Android ADB shell 中编辑文件吗?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/20258688/
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
Can I edit files inside the Android ADB shell?
提问by mk..
From android shell, is there a way I can edit a file?
从android shell,有没有办法编辑文件?
In order to edit files like .rc
and similar scripts, I am currently using adb pull
to pull them, then edit them and then push them back adb push
. This is certainly inefficient.
为了编辑类似.rc
和类似脚本的文件,我目前正在使用adb pull
拉它们,然后编辑它们,然后将它们推回adb push
。这当然是低效的。
Is there a way I can edit these files in android shell (like the vim editor in Linux shell)
有没有办法在 android shell 中编辑这些文件(比如 Linux shell 中的 vim 编辑器)
I have root permissions on my device. So if necessary, I can install root applications.
我在我的设备上拥有 root 权限。因此,如有必要,我可以安装根应用程序。
回答by Deepak Negi
You can create text files using:
您可以使用以下方法创建文本文件:
$ cat > filename.txt
You can add lines to a text files using:
您可以使用以下方法向文本文件添加行:
$ cat >> filename.txt
Both commands can be terminated using ctrl-D
.
这两个命令都可以使用ctrl-D
.
回答by Veener
You can install BusyBox from the F-Droid store and if you have rooted your device you are able to use vi
to edit files.
您可以从 F-Droid 商店安装 BusyBox,如果您已经植根设备,您就可以vi
用来编辑文件。
adb shell
busybox vi /sdcard/Download/test.txt
回答by Lohmar ASHAR
I've also noticed that the default shell is sh
and after entering bash
I could use nano
.
我还注意到默认的 shell 是sh
,输入后bash
我可以使用nano
.
回答by Tom Russell
While not answering the specific question, I will say there's an app called Termux in the Play Store that works for unrooted devices. It's only 200KB and supports vi
.
虽然没有回答具体问题,但我会说 Play 商店中有一个名为 Termux 的应用程序适用于无根设备。它只有 200KB 并支持vi
.
回答by CODE-REaD
A simplified version of vi for Android is contained in Busybox. Assuming you're running Windows, once you've installed Busybox (and you doneed root permissions to do so), I recommend you follow the instructions at https://stackoverflow.com/a/29033010/5025060to accomplish full screen text editing on your Android device from your Windows PC screen.
Busybox 中包含适用于 Android 的简化版 vi 。假设您运行的是 Windows,一旦您安装了 Busybox(并且您确实需要 root 权限才能这样做),我建议您按照https://stackoverflow.com/a/29033010/5025060上的说明完成全屏文本从 Windows PC 屏幕在 Android 设备上进行编辑。