读书人

adb shell 下令详解

发布时间: 2012-08-17 02:08:34 作者: rapoo

adb shell 命令详解
AndroidShell命令的使用可以将复制的文件等相关数据连接到手机中去。我们在这里为大家总结了几个Android Shell命令的常用方法。

大家可能对于Android这一手机操作系统有所了解,因为市面上很多智能手机都开始采用这一系统来抓住商业机遇。通过对它的深入了解,可以知道,adb是Android重要工具之一,以提供强大的特性,例如复制文件到设备或从设备复制文件。可以使用Android Shell命令行参数连接到手机本身,并发送基本的 shell 命令。

?

进入命令行,使用

?

    adb?shell?

?

进入到Android Shell命令模式,注意,这时候模拟器或者手机要启用并且正确接通。

Android程序架构基本内容概述Android判断网络状态方法详解Android单元测试源码解读Android Jni代码示例讲解Android安装卸载程序具体操作方法解析

?

?

在这个Android Shell命令环境中,可以:

显示网络配置,网络配置可显示多个网络连接。注意这多个网络连接:

lo 是本地或 loopback 连接。

tiwlan0 是 WiFi 连接,该连接由本地 DHCP 服务器提供一个地址。

显示 PATH 环境变量的内容。

执行 su 命令,以成为超级用户。

将目录改为 /data/app,其中存放用户应用程序。

列出包含某个应用程序的目录。Android 应用程序文件实际上是归档文件,可通过 WinZip 之类的软件查看。扩展名为 apk。
发出 ping 命令,查看 Google.com 是否可用。

从相同的命令提示符环境中,还可以与 SQLite 数据库交互,启动程序以及执行许多其他系统级任务。想像一下您正在连接到电话,因此这是非常了不起的功能。

?

一、adb命令

?

    Java代码? ?adb?get-product?//?获取设备的ID? ?adb?get-serialno?//?获取设备的序列号? ?adb?devices?//?得当前运行的模拟器/设备的实例的列表及每个实例的状态? ?adb?bugreport?//?查看bug报告?

?

二、Android Shell命令

?

通过adb shell命令进入shell后,执行下列命令。

?

1、访问数据库:

?

    sqlite3??

2、记录无线通讯日志

一般来说,无线通讯的日志非常多,在运行时没必要去记录,但我们还是可以通过命令,设置记录:

?

    logcat?-b?radio??

3、删除应用:

Android没有提供一个卸载应用的命令,需要自己手动删除:

?

    cd?/data/app? ?m?appName.apk? ?

注:[appName]为应用的名称;

?

三、可以在Android Shell命令下使用的一些linux命令

命令:

?

    ls?//?查看目录? ?date?//?打印或设置当前系统时间? ?cat?/proc/meminfo?//?查看内存信息? ?cat?/proc/cpuinfo?//?查看CPU信息??

Android Shell命令的相关内容就为大家介绍到这里。


命令行工具ADB(Andvoid Debug Bridge)是Android提供的一个通用的调试工具,借助这个工具,我们可以管理设备或手机模拟器的状态。

adb help

AndroidDebugBridgeversion 1.0.20

?-d??????????????????????- directs command to the only connected USB device

???????????????????????????returns an error if more than one USB device is present.

?-e??????????????????????- directs command to the only running emulator.

???????????????????????????returns an error if more than one emulator is running.

?-s <serial number>??????- directs command to the USB device or emulator with

???????????????????????????the given serial number

?-p <product name or path>??- simple product name like 'sooner', or

??????????????????????????????a relative/absolute path to a product

????????????????????????????????out directory like 'out/target/product/sooner'.

??????????????????????????????If -p is not specified, the ANDROID_PRODUCT_

????????????????????????????????environment variable is used, which must

??????????????????????????????be an absolute path.

?devices?????????????????- list all connected devices

?

device commands:

?adb push <local> <remote>???- copy file/dir to device

?adb pull <remote> <local>???- copy file/dir from device

?adb sync [ <directory> ]????- copy host->device only if changed

????????????????????????????????(see 'adb help all')

?adbshell???????????????????- run remote shell interactively

?adb shell <command>?????????- run remote shell command

?adb emu <command>???????????- run emulator console command

?adb logcat [ <filter-spec> ] - View device log

?adb forward <local> <remote> - forward socket connections

??????????????????????????????????tcp:<port>

??????????????????????????????????localabstract:<unix domain socket name>

??????????????????????????????????localreserved:<unix domain socket name>

??????????????????????????????????localfilesystem:<unix domain socket name>51Testing软件测试网;xm(L!V-S!HQ0Mb U

??????????????????????????????????dev:<character device name>51Testing软件测试网 UV0j J ]%mb{ bx8C

??????????????????????????????????jdwp:<process pid> (remote only)

?adb jdwp????????????????????- list PIDs of processes hosting a JDWP transport

?adb install [-l] [-r] <file> - push this package file to the device and install it

????????????????????????????????('-l' means forward-lock the app)

????????????????????????????????('-r' means reinstall the app, keeping its data)

?adb uninstall [-k] <package> - remove this app package from the device

????????????????????????????????('-k' means keep the data and cache directories)

?adb bugreport???????????????- return all information from the device

????????????????????????????????that should be included in a bug report.

?adb help????????????????????- show this help message

?adb version?????????????????- show version num

?

DATAOPTS:

?(no option)??????????????????- don't touch the data partition

?-w??????????????????????????- wipe the data partition

?-d??????????????????????????- flash the data partition

?

?

?adb wait-for-device?????????- block until device is online

?adb start-server????????????- ensure that there is a server running

?adb kill-server?????????????- kill the server if it is running

?adb get-state???????????????- prints: offline | bootloader | device

?adb get-product?????????????- prints: <product-id>

?adb get-serialno????????????- prints: <serial-number>

?adb status-window???????????- continuously print device status for a specified device

?adb remount?????????????????- remounts the /system partition on the device read-write

networking:

?adb ppp <tty> [parameters]??- Run PPP over USB.

?Note: you should not automatically start a PDP connection.

?<tty> refers to the tty for PPP stream. Eg. dev:/dev/omap_csmi_tty1

?[parameters] - Eg. defaultroute debug dump local notty usepeerdns

adb sync notes: adb sync [ <directory> ]

?<localdir> can be interpreted in several ways:

?

?- If <directory> is not specified, both /system and /data partitions will be updated.

?

?- If it is "system" or "data", only the corresponding partition??is updated.

?

?

ADB还可以进行以下的操作:

1、快速更新设备或手机模拟器中的代码,如应用或Android系统升级;

2、在设备上运行shell命令;

3、管理设备或手机模拟器上的预定端口;

4、在设备或手机模拟器上复制或粘贴文件;

5、安装.apk文件到仿真器上。

以下为一些常用的操作:

1、安装应用到模拟器:

adb install51Testing软件测试网N#nP vz

比较郁闷的是,Android并没有提供一个卸载应用的命令,只能自己手动删除:

adb shell

cd /data/app

rm app.apk

2、进入设备或模拟器的shell:

adb shell

通过上面的命令,就可以进入设备或模拟器的shell环境中,在这个LinuxShell中,你可以执行各种Linux的命令,另外如果只想执行一条shell命令,可以采用以下的方式:

adb shell [command]

如:adb shell dmesg会打印出内核的调试信息。

3、发布端口:

你可以设置任意的端口号,做为主机向模拟器或设备的请求端口。如:

adb forward tcp:5555 tcp:8000

4、复制文件:

你可向一个设备或从一个设备中复制文件,

复制一个文件或目录到设备或模拟器上:

adb push

如:adb pushtest.txt /tmp/test.txt

从设备或模拟器上复制一个文件或目录:

adb pull

如:adb pull /addroid/lib/libwebcore.so .

5、搜索模拟器/设备的实例:

取得当前运行的模拟器/设备的实例的列表及每个实例的状态:51Testing软件测试网K?;AO&O7Iz3F

adb devices

?

6、查看bug报告:

adb bugreport

?

7、记录无线通讯日志

一般来说,无线通讯的日志非常多,在运行时没必要去记录,但我们还是可以通过命令,设置记录:51Testing软件测试网en

adb shell51Testing软件测试网$PE [j/n0[ ? a4a

logcat -b radio

?

8、获取设备的ID和序列号:51Testing软件测试网h*Rl$N4F_U]

adb get-product51Testing软件测试网hSj*{haO%bz

adb get-serialno

?

9、访问数据库SQLite3

adb shell

sqlite3



安卓网的一个帖子,写得不错,记下来

ADB全称Android?Debug?Bridge, 是android sdk里的一个工具, 用这个工具可以直接操作管理android模拟器或者真实的andriod设备(如G1手机).

它的主要功能有:

读书人网 >其他数据库

热点推荐