Android 手机 ADB FastBoot 命令基本用法

时间:2022-08-24 18:03:34

adb用法:

准备:

1、在电脑上安装相应的USB驱动,在各分区置顶帖子有下载链接

2、手机进入设置->开发人员选项->勾选USB调试

adb devices 查看是否有设备

adb shell  ——登录到手机,可以执行各种linux命令。
运行后会出现上面提到的提示符,然后光标闪动等待输入命令,比如:
ls             ——列出当前目录下的目录和文件
cd xxx      ——进入xxx目录,可以是相对或绝对路径
其他常用命令很多,具体可以百度。

adb shell 
查看是否root、是否完全root

1、在电脑上依次点击:开始菜单->运行,然后输入cmd,回车后会弹出Dos窗口
2、输入adb shell,然后回车
3、此时注意手机的反应,如果手机弹出ADB shell请求超级用户权限,是否允许的对话框,请点击允许。这个只有第一次运行时会出现。
4、这时如果出现的是:root@android# 就代表手机已经完全root,很多功能需要在这个模式下才能正常工作。
    如果出现的是:shell@android$  则需要进一步判断

4、再输入su,然后回车
      此时注意手机的反应,如果手机弹出ADB shell请求超级用户权限,是否允许的对话框,请点击允许。这个只有第一次运行时会出现。
5、如果此时出现      root@android#    则代表手机已经root,不过kernel没有破解,称为不完全root,
这时adb和fastboot日常的需要root权限的操作应该都能正常运行。

如果出现报错,或仍然是    shell@android$    则代表手机没有root,adb和fastboot的很多功能不可以用

adb shell 备份导出分区, 可用ADB通过命令查看系统分区,命令如下:

su

cat /proc/mtd

假设mtd1对应 boot分区,mtd2对应system分区,备份导出boot.img与system.img命令如下:

cat /dev/mtd/mtd1 > /sdcard/boot.img

cat /dev/mtd/mtd2 > /sdcard/system.img

adb shell dd命令来刷recovery.img

adb shell

su

1)高通平台 :dd if=/data/local/tmp/recovery.img of=/dev/block/platform/msm_sdcc.1/by-name/recovery

2)MTK平台 :dd if=/data/local/tmp/recovery.img of=/dev/recovery

3)英伟达平台:dd if=/data/local/tmp/recovery.img of=/dev/block/platform/sdhci-tegra.3/by-name/SOS

adb remount(需要完全root)

——把system目录以读写的方式重新挂载,运行后就可以修改system目录下的东西了

adb push  object   dest
主要用于上传文件到手机,其中object是要上传的文件,如果在当前目录下则可以省略路径名,否则必须加路径,
dest是文件将要放到手机上的路径,也可以跟上文件名。

举例如下:
   adb push 1.zip /sdcard      ——把当前目录下的1.zip文件上传到手机上/sdcard目录下,文件名不变
   adb push 2.rar  /external_sd/22.rar   ——把当前目录下的2.rar文件上传到手机上/external_sd目录下,文件名变成22.rar
注意:这里的dest在上面提到的非root、不完全root和root环境下有着不同的限制。
非root环境、不完全root环境:常用的只有/sdcard、/external_sd,还有折腾可能用到/data/local/tmp
完全root环境: 运行adb remount之后dest可以是system目录或其子目录(部分特殊目录除外)。

adb pull  object   dest
    ——从手机下载文件到本地
object是手机上某个文件的路径,需要以/开头的完整路径,dest可以省略,省略的话是下载到当前目录。

举例如下:
adb pull /system/app/Maps.apk  ——把手机上/system/app/Maps.apk文件下载到当前目录下
adb pull /system/app/Maps.apk  2dir/ ——把手机上/system/app/Maps.apk文件下载到当前目录下的2dir目录下,前提是当前目录下存在2dir目录
adb pull /system/app/Maps.apk  2dir/Map.apk ——把手机上/system/app/Maps.apk文件下载到当前目录下
的2dir目录下,改名为Map.apk,前提是当前目录下存在2dir目录

adb reboot ——重启手机

adb reboot bootloader ——重启手机到fastboot模式     直接重启手机到fastboot模式,不用关机后再按组合键

adb reboot recovery ——重启手机到recovery模式    直接重启手机到fastboot模式,不用关机后再按组合键

adb install xxx.apk ——安装当前目录下的apk包到手机

fastboot命令

fastboot是配合手机的fastboot模式使用的一种工具。
可以在手机系统损坏(非砖)的情况下不依赖手机软件,而是使用本地的镜像操作手机。

下面列举常用的用法:

fastboot devices 查看是否有设备

fastboot boot boot.img|recovery.img  ——用当前目录下的boot.img或者recovery.img启动手机,具体如下
fastboot boot boot.img  ——用当前目录下的boot.img启动手机,在手机boot分区损坏的情况下可以用这个正常进入系统
fastboot boot recovery.img  ——用当前目录下的recovery.img启动手机到recovery模式,
这个和手机上现有的系统完全无关,只要本地的 recovery.img是以前能正常进rec的,那就绝对没问题。
那些官升或者刷rom后无法进入rec的其实都可以通过这种方式进入recovery 环境进行刷机、刷rec,刷各种zip……

上面介绍两种操作都是临时的,也就是说重启之后手机还是原来的状态,没有任何变动。
典型的应用场景是修改boot.img,可以用fastboot boot bootnew.img来测试新的boot.img,不对的话只需要重启手机。

下面这个的话就是真正改变了手机的boot分区,改写成了当前目录下 boot.img的内容。
fastboot flash boot boot.img  ——把当前目录下的boot.img刷入手机的boot分区。

fastboot flash recovery recovery.img  ——把当前目录下的recovery.img刷入手机的recovery分区。
fastboot flash system system.img  ——把当前目录下的system.img刷入手机的system分区。
fastboot flash userdata userdata.img 
——把当前目录下的userdata.img刷入手机的data分区。

fastboot erase system
fastboot erase cache
fastboot erase config
fastboot erase data
fastboot erase logs
fastboot erase factory

fastboot reboot —— 重启手机

Android系统的分区为:

boot分区对应 /boot
recovery分区对应 /recovery
system分区对应的目录 /system
userdata分区对应 /data
cache分区对应 /cache

Let’s move forward to the useful commands:

 
Commands Use
Basic ADB Commands
adb devices Shows a list of devices attached to the computer.
adb reboot Reboots a device connected to the PC.
adb reboot recovery Reboots a device into recovery mode.
adb reboot download Reboots the connected device into download mode. E.G Download mode on Samsung Galaxy devices.
adb reboot bootloader Reboots a device into Bootloader. Once in Bootloader, you can make further selections here.
adb reboot fastboot Reboots a connected device into Fastboot mode.
Installing / Uninstalling / Updating Apps with ADB. 
adb install <ApplicationpathPackagename>.apk ADB install let’s you install APK files directly to your phone. To use this command type adb install application path, as shown in the commands part and hit enter key and it will start installing the app on your phone. e.g adb install C:/Users/UsamaM/Desktop/CandyCrushSaga.apk. If process succeeds it will show you “Success” in the command window.
adb install -r <AplicationpathPackagename>.apk
 If you have already installed an app, and you just want to update it then this command will let you do so. e.g adb install -r C:/Users/UsamaM/Desktop/CandyCrushSaga.apk
adb unistall package_namee.g

adb uninstall com.android.chrome

Uninstalls and application from your device. The easiest way to find a package name is, install Package Name Viewer from the play store and find the name of the package under the App Name. If process succeeds it will show you “Success” in the command window.
adb uninstall -K package_namee.g

adb uninstall -K com.android.chrome

Uninstall an app but keeps it’s data and cache directories. If process succeeds it will show you “Success” in the command window.
 Push and Pull files 
 adb rootadb push >e.gadb push c:\users\UsamaM\desktop\Song.mp3 \system\media

adb push filepathonPC/filename.extension path.on.phone.toplace.the.file

 the adb push commands let’s you transfer any files to your phone from your PC. You simply need to provide the path of file on your PC and path where to place this file on your phone.
adb rootadb pull>e.gadb  pull \system\media\Song.mp C:\users\UsamaM\desktop

adb pull [Path of file on phone]  [Path on PC where to place the file]

 Similar to the adb push command. Using adb pull, you can simply pull any files from your phone.

Backing up system and installed apps. 

Before doing this, in your adb folder create a folder Backup and under the backup folder create two folders named SystemApps and InstalledApps.
These folders are necessary as you’ll be pushing the backed up apps to these folders.

adb pull /system/app backup/systemapps  backs up all the system apps of your phone to the Systemapps folder that you created in the ADB folder.
 adb pull /system/app backup/installedapps  backs up all the installed apps of your phone to the installedapps folder that you created in the ADB folder.
  Background Terminal
 adb shell  starts the background terminal.
exit exits the background terminal.
adb shell <command you want>e.g adb shell su switches to the root of your phone. Please make sure that you’re rooted in case you wish to use adb  shell su.

Fastboot commands

To flash files using fastboot, place the desired files in Fastboot folder or Platform-tools folder that you obtained after installation of Android SDK tools.

Fastboot Flash File.zip  Flashes a .zip file to your phone, when your phone is connected in Fastboot mode.
Fastboot Flash recovery recoveryname.img Flashes a recovery to your phone when it’s connected in Fastboot mode.
Fastboot flash boot bootname.img Flashes a boot or kernel image when your phone is connected in Fastboot mode.
Fastboot getvar cid shows you the CID of your phone.
Fastboot oem writeCID xxxxx writes the super CID.
fastboot erase system
fastboot erase data
fastboot erase cache
In case you want to restore a nandroid backup, you’ll have to delete the current system/data/cache of your phone first. Before doing this, it is always recommended to have backed up your system using a custom recovery>backup option and copy the backed up .img files to Fastboot or Platform-tools folder in Android SDK folder. Then performing these commands will erase everything.
fastboot flash system system.img
fastboot flash data data.img
fastboot flash cache cache.img
These commands will restore the backup that you made using a custom recovery on your phone and placed in the Fastboot folder under Android SDK tools.
fastboot oem get_unlock_data
fastboot oem unlock UNIQUE_KEY

fastboot oem get_identifier_token

fastboot oem flash Unlock_code.bin

fastboot oem lock
These commands help you to get the identifier token of your phone that can be used for unlocking the bootloader. The second command helps your to flash the bootloader unlock code, and the 3rd commands helps you to lock your phone’s bootloader once again if locking it is actually allowed.

Logcat

adb logcat Shows you the real time logs of your phone, these logs represent the ongoing process on your device.It is recommended that you run this command while your device boots up to check what’s going on.
adb logcat > logcat.txt Creates a .txt file containing the logs in the Platform-tools folder or Fastboot folder in Android SDK tools directory.

Android 手机 ADB FastBoot 命令基本用法的更多相关文章

  1. Android 执行 adb shell 命令

    Android 执行Adb shell 命令大多需要root权限,Android自带的Runtime. getRuntime().exec()容易出错,在网上找到了一个执行adb shell命令的类 ...

  2. Android&&num;160&semi;通过adb&&num;160&semi;shell命令查看内存,CPU,启动时间,电量等信息

    Android 通过adb shell命令查看内存,CPU,启动时间,电量等信息   by:授客 QQ:1033553122 1.  查看内存信息 1)查看所有内存信息 命令: dumpsys mem ...

  3. Android:adb shell 命令详解

    安卓系统是基于Linux系统开发,也就支持常见的Linux的命令,这些命令都保存在手机“/system/bin”的目录下,通过adb shell 便可以调用这些命令. 进入“/system/bin”该 ...

  4. adb logcat 命令行用法

    作者 :万境绝尘  转载请著名出处 eclipse 自带的 LogCat 工具太垃圾了, 开始用 adb logcat 在终端查看日志; 1. 解析 adb logcat 的帮助信息 在命令行中输入  ...

  5. 【android】adb常用命令

    ADB常用命令: [adb help]获取帮助 [adb get-serialno]获取设备串号 [adb -s <serialNumber> <command>]给特定设备发 ...

  6. 如何设置Android手机的sqlite3命令环境

    1.在PC环境下启动一个模拟器(不是手机) 2.查看模拟器 /systen/xbin是否有sqlite3命令 adb shell cd /system/xbin ls 3.把模拟器 /system/x ...

  7. Android 神兵利器—— Adb 常用命令

    总结的Android工具类文章: Android 神兵利器-- Adb 常用命令 Android 神兵利器-- Git 常用命令 Adb的全称为Android Debug Bridge,是管理andr ...

  8. 54&period; Android中adb常用命令及应用常用目录

    本文主要介绍adb常用命令及应用常用目录.1.adb常用命令adb devices列出所有连接的android设备.以下命令都是对单个devices而言,如果存在多个devices的话,下面的命令都需 ...

  9. 【android】 adb logcat命令查看并过滤android输出log

    cmd命令行中使用adb logcat命令查看android系统和应用的log,dos窗口按ctrl+c中断输出log记录. logcat日志中的优先级/tag标记: android输出的每一条日志都 ...

随机推荐

  1. winform学习-----理解小概念-20160518

    一.设置滚动,滚动列遮住内容的解决办法 1.datagridview三个属性:autosizecolumsmode none autosizeRowsmode   none dock  fill 2. ...

  2. 关于inline-block 元素之间为何会产生间隔

    关于inline-block 元素之间为何会产生间隔 现象: <body> <input type="text"> <input type=&quot ...

  3. &lbrack;topcoder&rsqb;ActivateGame

    http://community.topcoder.com/stat?c=problem_statement&pm=10750&rd=14153 http://apps.topcode ...

  4. 【转】HashSet的用法

    原文网址:http://blog.csdn.net/aidesudi/article/details/4720201 Java代码 public class TestHashSet { public  ...

  5. Oracle控制文件操作

    控制文件是连接instance和 database的纽带.记录了database的结构信息. 控制文件是1个2进制文件.记录的是当前database的状态. 控制文件可以有多个,在参数文件中通过con ...

  6. 【Java入门提高篇】Day11 Java代理——JDK动态代理

    今天来看看Java的另一种代理方式--JDK动态代理 我们之前所介绍的代理方式叫静态代理,也就是静态的生成代理对象,而动态代理则是在运行时创建代理对象.动态代理有更强大的拦截请求功能,因为可以获得类的 ...

  7. Codeforces 777C Alyona and Spreadsheet

    C. Alyona and Spreadsheet time limit per test:1 second memory limit per test:256 megabytes input:sta ...

  8. 列表&amp&semi;元组的内置方法

    标红为元组可以使用

  9. 0513JS数组内置方法、数学函数、时间函数

    |数组中常用的内置方法|-push()与pop()|--push()是往数组的尾部添加,同时返回新数组的长度 var attr = [1,2,3,4,5];var attr2 = [6,7,8,9,0 ...

  10. Spring Cloud Config 分布式配置中心使用教程

    一.简介 在分布式系统中,由于服务数量巨多,为了方便服务配置文件统一管理,实时更新,所以需要分布式配置中心组件.在Spring Cloud中,有分布式配置中心组件spring cloud config ...