1. 查看IP

adb shell netcfg

2. 查看挂载设备

adb devices

3. 将本地端口转发至手机端口

adb forward tcp: tcp: // PC上所有6100端口通信数据将被重定向到手机端7100端口server上
或者
adb forward tcp: local:logd // PC上所有6100端口通信数据将被重定向到手机端UNIX类型socket上

4. 打开指定应用

am start -n {包(package)名}/{包名}.{活动(activity)名称}

5. 启动相关应用

calendar(日历)的启动方法为:
# am start -n com.android.calendar/com.android.calendar.LaunchActivity AlarmClock(闹钟)的启动方法为:
# am start -n com.android.alarmclock/com.android.alarmclock.AlarmClock Music 和 Video(音乐和视频)的启动方法为:
# am start -n com.android.music/com.android.music.MusicBrowserActivity
# am start -n com.android.music/com.android.music.VideoBrowserActivity
# am start -n com.android.music/com.android.music.MediaPlaybackActivity Camera(照相机)的启动方法为:
# am start -n com.android.camera/com.android.camera.Camera Browser(浏览器)的启动方法为:
# am start -n com.android.browser/com.android.browser.BrowserActivity 启动浏览器 :
#am start -a android.intent.action.VIEW -d http://www.google.cn/ 拨打电话 :
#am start -a android.intent.action.CALL -d tel: 启动 google map 直接定位到北京 :
#am start -a android.intent.action.VIEW geo:,?q=beijing 一般情况希望,一个Android应用对应一个工程。值得注意的是,有一些工程具有多个活动(activity),而有一些应用使用一个工程。例如:在Android界面中,Music和Video是两个应用,但是它们使用的都是packages/apps/Music这一个工程。而在这个工程的AndroidManifest.xml文件中,有包含了不同的活动(activity)。

6. 安装应用

adb install APK_FILE //安装应用, APK_FILE 可以是包名,也可以是apk名
adb install -r APK_FILE //重新安装应用

7. 卸载应用

adb uninstall APK_FILE

8. 启动应用的某一个页面

adb shell am start PACKAGE_NAME/ACTIVITY_IN_PACKAGE
adb shell am start PACKAGE_NAME/FULLY_QUALIFIED_ACTIVITY

9. 进入设备shell

adb shell

10. 截屏:获得一个屏幕截图且使用shell screencap通过perl输出到本地目录。参照:博客

adb shell screencap -p | perl -pe 's/\x0D\x0A/\x0A/g' > screen.png

11. 解锁

adb shell input keyevent 

12 显示日志

adb logcat //显示所有日志

adb logcat -s TAG_NAME //根据标签过滤
adb logcat -s TAG_NAME_1 TAG_NAME_2
//example
adb logcat -s TEST
adb logcat -s TEST MYAPP adb logcat "*:PRIORITY"//显示特定优先级的日志
// example
adb logcat "*:W"
//优先级说明:
# V — 细则 (最低优先级),D — 调试,I — 信息,W — 警告
# E — 错误,F — 致命,S — 静默 (最高优先级,不会打印任何信息) adb logcat | grep "SEARCH_TERM" //使用grep过滤日志
adb logcat | grep "SEARCH_TERM_1\|SEARCH_TERM_2"
//example
adb logcat | grep "Exception"
adb logcat | grep "Exception\|Error"

13 清除日志

adb logcat -c

以下内容来说官网:

The table below lists all of the supported adb commands and explains their meaning and usage.

Category Command Description Comments
Options -d Direct an adb command to the only attached USB device. Returns an error if more than one USB device is attached.
-e Direct an adb command to the only running emulator instance. Returns an error if more than one emulator instance is running.
-s <serialNumber> Direct an adb command a specific emulator/device instance, referredto by its adb-assigned serial number (such as "emulator-5556"). If not specified, adb generates an error.
General devices Prints a list of all attached emulator/device instances. See Querying for Emulator/Device Instances for more information.
help Prints a list of supported adb commands.  
version Prints the adb version number.  
Debug logcat [<option>] [<filter-specs>] Prints log data to the screen.  
bugreport Prints dumpsys, dumpstate, and logcat data to the screen, for the purposes of bug reporting.  
jdwp Prints a list of available JDWP processes on a given device. You can use the forward jdwp:<pid> port-forwarding specification to connect to a specific JDWP process. For example:
adb forward tcp:8000 jdwp:472
jdb -attach localhost:8000
Data install <path-to-apk> Pushes an Android application (specified as a full path to an .apk file) to the data file of an emulator/device.  
pull <remote> <local> Copies a specified file from an emulator/device instance to your development computer.  
push <local> <remote> Copies a specified file from your development computer to an emulator/device instance.  
Ports and Networking forward <local> <remote> Forwards socket connections from a specified local port to a specified remote port on the emulator/device instance. Port specifications can use these schemes:

  • tcp:<portnum>
  • local:<UNIX domain socket name>
  • dev:<character device name>
  • jdwp:<pid>
ppp <tty> [parm]... Run PPP over USB.

  • <tty> — the tty for PPP stream. For example dev:/dev/omap_csmi_ttyl.
  • [parm]... — zero or more PPP/PPPD options, such as defaultroute,local,notty, etc.

Note that you should not automatically start a PDP connection.

 
Scripting get-serialno Prints the adb instance serial number string. See Querying for Emulator/Device Instances for more information.
get-state Prints the adb state of an emulator/device instance.
wait-for-device Blocks execution until the device is online — that is, until the instance state isdevice. You can prepend this command to other adb commands, in which caseadb
will wait until the emulator/device instance is connected beforeissuing
the other commands. Here's an example:

adb wait-for-device shell getprop

Note that this command does notcause adb to wait until the entire system is fully booted. For thatreason, you should not prepend it to other commands that require afully booted system. As an example, theinstall requires the Android package manager, which is available only after the system is fully booted. A command such as

adb wait-for-device install <app>.apk

would issue the installcommand as soon as the emulator or device instance connected to the adbserver, but before the Android system was fully booted, so it wouldresult in an error.

Server start-server Checks whether the adb server process is running and starts it, if not.  
kill-server Terminates the adb server process.  
Shell shell Starts a remote shell in the target emulator/device instance. See Issuing Shell Commands for more information.
shell [<shellCommand>] Issues a shell command in the target emulator/device instance and then exits the remote shell.

Issuing Shell Commands

Adb provides an ash shell that you can use to run a variety of commands on an emulator or device. The command binaries are stored in the file system of the emulator or device, in this location:

/system/bin/...

You can use the shell command to issue commands, with or without entering the adb remote shell on the emulator/device.

To issue a single command without entering a remote shell, use the shell command like this:

adb [-d|-e|-s {<serialNumber>}] shell <shellCommand>

To drop into a remote shell on a emulator/device instance, use the shell command like this:

adb [-d|-e|-s {<serialNumber>}] shell

When you are ready to exit the remote shell, use CTRL+D or exit to end the shell session.

The sections below provide more information about shell commands that you can use.

Examining sqlite3 Databases from a Remote Shell

From an adb remote shell, you can use the sqlite3 command-line program to manage SQLite databases created by Android applications. Thesqlite3 tool includes many useful commands, such as.dump to print out the contents of a table and.schema to print the SQL CREATE statement for an existing table. The tool also gives you the ability to execute SQLite commands on the fly.

To use sqlite3, enter a remote shell on the emulator instance, as described above, then invoke the tool using thesqlite3 command. Optionally, when invokingsqlite3you can specify the full path to the database you want to explore.Emulator/device instances store SQLite3 databases in the folder/data/data/<package_name>/databases/.

Here's an example:

$ adb -s emulator-5554 shell
# sqlite3 /data/data/com.example.google.rss.rssexample/databases/rssitems.db
SQLite version 3.3.12
Enter ".help" for instructions
.... enter commands, then quit...
sqlite> .exit

Once you've invoked sqlite3, you can issue sqlite3 commands in the shell. To exit and return to the adb remote shell, useexit orCTRL+D.

UI/Application Exerciser Monkey

The Monkey is a program that runs on your emulator or device and generates pseudo-randomstreams of user events such as clicks, touches, or gestures, as well as a number of system-level events. You can use the Monkey to stress-test applications that you are developing,in a random yet repeatable manner.

The simplest way to use the monkey is with the following command, which will launch yourapplication and send 500 pseudo-random events to it.

$ adb shell monkey -v -p your.package.name 500

For more information about command options for Monkey, see the complete UI/Application Exerciser Monkey documentation page.

Other Shell Commands

The table below lists several of the adb shell commands available.For a complete list of commands and programs, start an emulatorinstance and use theadb -help command.

adb shell ls /system/bin

Help is available for most of the commands.

Shell Command Description Comments
dumpsys Dumps system data to the screen. The Dalvik Debug Monitor Service (DDMS) tool offers integrated debug environment that you may find easier to use.
dumpstate Dumps state to a file.
logcat [<option>]... [<filter-spec>]... Enables radio logging and prints output to the screen.
dmesg Prints kernel debugging messages to the screen.
start Starts (restarts) an emulator/device instance.  
stop Stops execution of an emulator/device instance.  

Enabling logcat Logging

The Android logging system provides a mechanism for collecting andviewing system debug output. Logs from various applications andportions of the system are collected in a series of circular buffers,which then can be viewed and filtered by thelogcat command.

Using logcat Commands

You can use the logcat command to view and follow the contents of the system's log buffers. The general usage is:

[adb] logcat [<option>] ... [<filter-spec>] ...

The sections below explain filter specifications and the command options. See Listing of logcat Command Options for a summary of options.

You can use the logcat command from your developmentcomputer or from a remote adb shell in an emulator/device instance. Toview log output in your development computer, you use

$ adb logcat

and from a remote adb shell you use

# logcat

Filtering Log Output

Every Android log message has a tag and a priority associated with it.

  • The tag of a log message is a short string indicating the systemcomponent from which the message originates (for example, "View" forthe view system).
  • The priority is one of the following character values, ordered from lowest to highest priority:
    • V — Verbose (lowest priority)
    • D — Debug
    • I — Info
    • W — Warning
    • E — Error
    • F — Fatal
    • S — Silent (highest priority, on which nothing is ever printed)

You can obtain a list of tags used in the system, together with priorities, by runninglogcat and observing the first two columns of each message, given as<priority>/<tag>.

Here's an example of logcat output that shows that the message relates to priority level "I" and tag "ActivityManager":

I/ActivityManager(  585): Starting activity: Intent { action=android.intent.action...}

To reduce the log output to a manageable level, you can restrict log output usingfilter expressions.Filter expressions let you indicate to the system the tags-prioritycombinations that you are interested in — the system suppresses othermessages for the specified tags.

A filter expression follows this format tag:priority ..., where tag indicates the tag of interest and priority indicates the minimumlevel of priority to report for that tag. Messages for that tag at orabove the specified priority are written to the log. You can supply anynumber oftag:priority specifications in a single filter expression. The series of specifications is whitespace-delimited.

Here's an example of a filter expression that suppresses all logmessages except those with the tag "ActivityManager", at priority"Info" or above, and all log messages with tag "MyApp", with priority"Debug" or above:

adb logcat ActivityManager:I MyApp:D *:S

The final element in the above expression, *:S, setsthe priority level for all tags to "silent", thus ensuring only logmessages with "View" and "MyApp" are displayed. Using*:Sis an excellent way to ensure that log output is restricted to thefilters that you have explicitly specified — it lets your filters serveas a "whitelist" for log output.

The following filter expression displays all log messages with priority level "warning" and higher, on all tags:

adb logcat *:W

If you're running logcat from your development computer(versus running it on a remote adb shell), you can also set a defaultfilter expression by exporting a value for the environment variableANDROID_LOG_TAGS:

export ANDROID_LOG_TAGS="ActivityManager:I MyApp:D *:S"

Note that ANDROID_LOG_TAGS filter is not exported to the emulator/device instance, if you are runninglogcat from a remote shell or usingadb shell logcat.

Controlling Log Output Format

Log messages contain a number of metadata fields, in addition to thetag and priority. You can modify the output format for messages so thatthey display a specific metadata field. To do so, you use the-v option and specify one of the supported output formats listed below.

  • brief — Display priority/tag and PID of originating process (the default format).
  • process — Display PID only.
  • tag — Display the priority/tag only.
  • thread — Display process:thread and priority/tag only.
  • raw — Display the raw log message, with no other metadata fields.
  • time — Display the date, invocation time, priority/tag, and PID of the originating process.
  • long — Display all metadata fields and separate messages with a blank lines.

When starting logcat, you can specify the output format you want by using the-v option:

[adb] logcat [-v <format>]

Here's an example that shows how to generate messages in thread output format:

adb logcat -v thread

Note that you can only specify one output format with the -v option.

Viewing Alternative Log Buffers

The Android logging system keeps multiple circular buffers for logmessages, and not all of the log messages are sent to the defaultcircular buffer. To see additional log messages, you can startlogcat with the-b option, to request viewing of an alternate circular buffer. You can view any of these alternate buffers:

  • radio — View the buffer that contains radio/telephony related messages.
  • events — View the buffer containing events-related messages.
  • main — View the main log buffer (default)

The usage of the -b option is:

[adb] logcat [-b <buffer>]

Here's an example of how to view a log buffer containing radio and telephony messages:

adb logcat -b radio

Viewing stdout and stderr

By default, the Android system sends stdout and stderr (System.out andSystem.err) output to/dev/null.Inprocesses that run the Dalvik VM, you can have the system write a copyof the output to the log file. In this case, the system writes themessages to the log using the log tagsstdout andstderr, both with priorityI.

To route the output in this way, you stop a running emulator/device instance and then use the shell commandsetprop to enable the redirection of output. Here's how you do it:

$ adb shell stop
$ adb shell setprop log.redirect-stdio true
$ adb shell start

The system retains this setting until you terminate theemulator/device instance. To use the setting as a default on theemulator/device instance, you can add an entry to/data/local.propon the device.

Listing of logcat Command Options

Option Description
-b <buffer> Loads an alternate log buffer for viewing, such as event or radio. The main buffer is used by default. See Viewing Alternative Log Buffers.
-c Clears (flushes) the entire log and exits.
-d Dumps the log to the screen and exits.
-f <filename> Writes log message output to <filename>. The default is stdout.
-g Prints the size of the specified log buffer and exits.
-n <count> Sets the maximum number of rotated logs to <count>. The default value is 4. Requires the-r option.
-r <kbytes> Rotates the log file every <kbytes> of output. The default value is 16. Requires the-f option.
-s Sets the default filter spec to silent.
-v <format> Sets the output format for log messages. The default is brief format. For a list of supported formats, seeControlling Log Output Format.

Stopping the adb Server

In some cases, you might need to terminate the adb server processand then restart it. For example, if adb does not respond to a command,you can terminate the server and restart it and that may resolve theproblem.

To stop the adb server, use the kill-server. You can then restart the server by issuing any adb command.

												

Adb shell 常用命令的更多相关文章

  1. 移动端 - adb shell常用命令

    一.文件操作相关命令 //进入设备 adb shell //进入指定目录"/data/local/tmp" cd /data/local/tmp //查看目录 ls //进入根目录 ...

  2. Android adb shell 常用命令

    Ø  简介 adb 命令是 Android SDK 中自带的一个调试工具,可以调试电脑中的手机或者模拟器,使用 adb 命令前需要将 sdk 中的 platform-tools 目录添加到环境变量中. ...

  3. adb shell常用命令

    一.文件操作相关命令 1.文件操作命令 子命令 参数 说明 cd 无 进入目录 cat [-beflnstuv] [-B bsize] [file...] 查看文件内容-n:显示行号-b:显示行号,但 ...

  4. Appium无线连接安卓终端方法 + ADB Shell常用命令(持续更新)

    ADB无线连接手机的方法1)手机与PC有线相连 - 检查是否连接正常: adb devices - 执行以下命令:adb tcpip 5555 # 当前9001       - 成功提示:restar ...

  5. adb shell常用命令总结

    一.文件操作相关命令 1.文件操作命令 子命令 参数 说明 cd 无 进入目录 cat [-beflnstuv] [-B bsize] [file...] 查看文件内容-n:显示行号-b:显示行号,但 ...

  6. 安卓性能测试之 adb shell 常用命令

    pm list packages 列出包名adb shell pm list packages:列出所有的包名.adb shell dumpsys package:列出所有的安装应用的信息adb sh ...

  7. (转)Hbase shell 常用命令(1)

    Hbase shell 常用命令(1) link:http://blog.csdn.net/scutshuxue/article/details/6988348 下面我们看看HBase Shell的一 ...

  8. win7 cmd终端连接android手机运行adb shell脚本命令

    win7 cmd终端连接android手机运行adb shell脚本命令 (2013-03-22 20:13:57) 转载▼ 标签: android it shell 连接 linux 分类: 嵌入式 ...

  9. Shell 常用命令总结

      Shell常用命令总结 1  ls命令:列出文件 ls -la 列出当前目录下的所有文件和文件夹 ls a* 列出当前目录下所有以a字母开头的文件 ls -l *.txt 列出当前目录下所有后缀名 ...

随机推荐

  1. Sumdiv(各种数学)

    http://poj.org/problem?id=1845 题意:求A^B的所有约数的和再对9901取模: 做了这个学到了N多数学知识: 一:任意一个整数都可以唯一分解成素因子的乘积:A = p1^ ...

  2. 【数学】【NOIp2012】同余方程 题解 以及 关于扩展欧几里得与同余方程

    什么是GCD? GCD是最大公约数的简称(当然理解为我们伟大的党也未尝不可).在开头,我们先下几个定义: ①a|b表示a能整除b(a是b的约数) ②a mod b表示a-[a/b]b([a/b]在Pa ...

  3. openvpn服务器端配置文件

  4. xargs 参数

    hadoop fs -ls /source/recommend/at_access | awk -F "/" '{print $NF}' | grep -v $(date +%Y% ...

  5. 【repost】如何学好编程 (精挑细选编程教程,帮助现在在校学生学好编程,让你门找到编程的方向)四个方法总有一个学好编程的方法适合你

    方法(一)编了这么久的程序,一直想找机会总结下其中的心得和方法,但回想我这段编程道路,又很难说清楚,如果按照我走过的所有路来说,显然是不可能的!当我看完了云风的<游戏之旅--编程感悟>和梁 ...

  6. FreeRTOS学习笔记——任务间使用队列同步数据

    1.前言 在嵌入式操作系统中队列是任务间数据交换的常用手段,队列是生产者消费者模型的重要组成部分.FreeRTOS的队列简单易用,下面结合一个具体例子说明FreeRTOS中的队列如何使用. 2.参考代 ...

  7. 【Deep Learning学习笔记】Dynamic Auto-Encoders for Semantic Indexing_Mirowski_NIPS2010

    发表于NIPS2010 workshop on deep learning的一篇文章,看得半懂. 主要内容: 是针对文本表示的一种方法.文本表示可以进一步应用在文本分类和信息检索上面.通常,一篇文章表 ...

  8. android 窗体透明的,黑暗度等的设置技巧

    设置透明度(这是窗体本身的透明度,非背景) 1 WindowManager.LayoutParams lp=getWindow().getAttributes(); 2 lp.alpha=0.3f; ...

  9. Reso | liunx下longeneQQ和搜狗拼音

    sogoupinyin_2.0.0.0078_amd64.deb:   http://pan.baidu.com/s/1eSDLvEU WineQQ7.8-20151109-Longene .deb: ...

  10. HDU 4442 Physical Examination(关于贪心排序)

    这个题目用贪心来做,关键是怎么贪心最小,那就是排序的问题了. 加入给定两个数a1, b1, a2, b2.那么如果先选1再选2的话,总的耗费就是a1 + a1 * b2 + a2; 如果先选2再选1, ...