android:shell命令
adb是Android重要⼯具之⼀,以提供强⼤的特性,例如复制⽂件到设备或从设备复制⽂件。可以使⽤Android Shell命令⾏参数连接到⼿机本⾝,并发送基本的 shell 命令。
进⼊命令⾏,使⽤
1. adb shell
进⼊到Android Shell命令模式,注意,这时候模拟器或者⼿机要启⽤并且正确接通
在这个Android Shell命令环境中,可以:
显⽰⽹络配置,⽹络配置可显⽰多个⽹络连接。注意这多个⽹络连接:
lo 是本地或 loopback 连接。
tiwlan0 是 WiFi 连接,该连接由本地 DHCP 服务器提供⼀个地址。
显⽰ PATH 环境变量的内容。
执⾏ su 命令,以成为超级⽤户。
将⽬录改为 /data/app,其中存放⽤户应⽤程序。
列出包含某个应⽤程序的⽬录。Android 应⽤程序⽂件实际上是归档⽂件,可通过 WinZip 之类的软件查看。扩展名为 apk。
发出 ping 命令,查看 Google 是否可⽤。
从相同的命令提⽰符环境中,还可以与 SQLite 数据库交互,启动程序以及执⾏许多其他系统级任务。想像⼀下您正在连接到电话,因此这是⾮常了不起的功能。
⼀、adb命令
1. Java代码
2. adb get-product // 获取设备的ID
3. adb get-serialno // 获取设备的序列号
4. adb devices // 得当前运⾏的模拟器/设备的实例的列表及每个实例的状态
5. adb bugreport // 查看bug报告
⼆、Android Shell命令
通过adb shell命令进⼊shell后,执⾏下列命令。
1、访问数据库:
1. sqlite3
2、记录⽆线通讯⽇志:
⼀般来说,⽆线通讯的⽇志⾮常多,在运⾏时没必要去记录,但我们还是可以通过命令,设置记录:
1. logcat -b radio
3、删除应⽤:
Android没有提供⼀个卸载应⽤的命令,需要⾃⼰⼿动删除:
1. cd /data/app
2. m appName.apk
注:[appName]为应⽤的名称;
三、可以在Android Shell命令下使⽤的⼀些linux命令
命令:
1. ls // 查看⽬录
2. date // 打印或设置当前系统时间
3. cat /proc/meminfo // 查看内存信息
4. 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')
adb shell                  - 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>
dev:<character device name>
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 install
⽐较郁闷的是,Android并没有提供⼀个卸载应⽤的命令,只能⾃⼰⼿动删除:
adb shell
cd /data/app
rm app.apk
2、进⼊设备或模拟器的shell:
adb shell
通过上⾯的命令,就可以进⼊设备或模拟器的shell环境中,在这个Linux Shell中,你可以执⾏各种Linux的命令,另外如果只想执⾏⼀条shell命令,可以采⽤以下的⽅式:
adb shell [command]
如:adb shell dmesg会打印出内核的调试信息。
3、发布端⼝:
你可以设置任意的端⼝号,做为主机向模拟器或设备的请求端⼝。如:
adb forward tcp:5555 tcp:8000
4、复制⽂件:
android模拟点击你可向⼀个设备或从⼀个设备中复制⽂件,
复制⼀个⽂件或⽬录到设备或模拟器上:
adb push
如:adb /
从设备或模拟器上复制⼀个⽂件或⽬录:
adb pull
如:adb pull /addroid/lib/libwebcore.so .
5、搜索模拟器/设备的实例:
取得当前运⾏的模拟器/设备的实例的列表及每个实例的状态:
adb devices
6、查看bug报告:
adb bugreport
7、记录⽆线通讯⽇志:
⼀般来说,⽆线通讯的⽇志⾮常多,在运⾏时没必要去记录,但我们还是可以通过命令,设置记录:
adb shell
logcat -b radio
8、获取设备的ID和序列号:
adb get-product
adb get-serialno
9、访问数据库SQLite3
adb shell
sqlite3
安卓⽹的⼀个帖⼦,写得不错,记下来
ADB全称Android Debug Bridge, 是android sdk⾥的⼀个⼯具, ⽤这个⼯具可以直接操作管理android模拟器或者真实的andriod设备(如G1⼿机).
它的主要功能有:
运⾏设备的shell(命令⾏)
管理模拟器或设备的端⼝映射
计算机和设备之间上传/下载⽂件
将本地apk软件安装⾄模拟器或android设备
ADB是⼀个客户端-服务器端程序, 其中客户端是你⽤来操作的电脑, 服务器端是android设备.
先说安装⽅法, 电脑上需要安装客户端. 客户端包含在sdk⾥. 设备上不需要安装, 只需要在⼿机上打开选项settings-applications-development-USBdebugging.
对于Mac和Linux⽤户, 下载好的sdk解压后, 可以放~或者任意⽬录. 然后修改~/.bash_profile⽂件, 设置运⾏环境指向sdk的tools⽬录.
具体是打开~/.bash_profile⽂件(如果没有此⽂件也可以⾃⾏添加), 在⾥⾯加⼊⼀⾏:
export PATH=${PATH}:<;你的sdk⽬录>/tools
然后就可以使⽤adb命令了.
ADB常⽤的⼏个命令
1. 查看设备
adb devices
这个命令是查看当前连接的设备, 连接到计算机的android设备或者模拟器将会列出显⽰
2. 安装软件

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。