SoFunction
Updated on 2025-03-04

Detailed explanation of commonly used commands for adb shell

1. File operation related commands

1. File operation commands

Subcommand parameter illustrate
cd none Go to the directory
cat [-beflnstuv] [-B bsize] [file...] View file content
-n: Show line number
-b: Display line numbers, but ignore empty lines
-s: Display line number, continuous blank lines are marked as one line
df none List partition list
du [-H] [-L] [-P] [-a] [-d depth] [-s] [-cghikmnrx] [file...] Query the disk usage space of a file or directory
ls [-a] [-i] [-l] [-n] [-s] List the contents of the directory
-a: List all files, including hidden files
-i: The index information of the i node of the output file
-l List the details of the file
-n: Use the GUID of the number instead of the name
-s: output the size of the file
grep [-abcDEFGHhliJLlmnOoPqRSsUVvwxZz]
[-A num]
[-B num]
[-C[num]
[-e pattern]
[-f file]
[--binary-files=value]
[--color=when]
[--context=num]
[--directories=action]
[--lable]
[--line-buffered]
[pattern]                             [file...]
Specify the file to search for specific content and output the line containing these contents standard output
mkdir -p,-parents Create a directory
-p, --parents: Recursively create directory
touch touch [-alm] [-t YYYYMMDD [.HHMMSS]] < file > Create a file
rm rm [-f\|-i][-dPRrvWx]file Delete files
-f: Forced delete file, the system does not prompt
-i: interactive deletion, prompt before deletion
-d: Change the hard connection data to 0, delete the file
-r: Forced delete folders including files inside
mv mv[-fiv]source target Move files (equivalent to cutting)
-f: Forced move, if the file already has a target, it will be directly overwritten
-i: If the target file already exists, it will ask whether to overwrite it
rmdir rmdir[-p] directory Delete directory
-p: Recursively delete directories, only empty directories can be deleted
dd dd[operand...]
dd if =source of=targe
Copy the file

2. File permission command and other file commands

Subcommand parameter illustrate
chomd chomd[OPTION]< MODE > < FILE > File permission modification
-R: Recursively change files and directories
-h: Not following symbolic connection
chown chown[-R[-H\|-L\|-P]] [-fhv]
owner : group | owner | : group file
Change the owner and group of a file or directory
md5 md5 file... Query the MD5 value of the file
mount mount [-r] [-w] [-o options] [-t type] device directory Mounting device information
umount umount < path > Uninstall partition mount
cmp cmp[-b][-l][-n count] file1 file2 To indicate whether there are differences between the two files
ln ln [-fhinsv] file1 file2
ln [-fhinsv] file...directory
Used to create a connection between files. After creating a connection, any file of the two files will change the content of the file and the other file will be synchronized accordingly.

3. Command usage example:

//Enter the deviceadb shell
//Enter the specified directory "/data/local/tmp"cd /data/local/tmp
//View the directoryls
//Enter the root directorycd /
//Enter the specified directory "/data/local/tmp"cd /data/local/tmp
//View partition listdf
//Create a .txt file named 1 in the current directory (create two more, name them 2 and 3, so that you can continue to learn and use them later)touch 
// List the detailed information of all files (including hidden files), and you can check whether the created just now is successful.ls -al
//Create a folder named 1 in the current directorymkdir1
// List the detailed information of all files (including hidden files). You can check whether the directory folder just now is successfully created.ls -al
//Create a recursive directory under the current directory, 2 contains 3, 3 contains 4mkdir -p 2/3/4
//Return to the previous directory and operate it twice in a row to return to the cd /data/local/tmp directorycd ..
//Move the file to 1 directory (cut effect)mv  1
//Enter 1 directory cd 1// Check if it has moved inls
//Return to the previous directorycd ..
//Copy the file in the current directory to a directory named 2 and name itdd if==2/
//Enter into directory 2cd 2
// Check whether the previous file operation was successfulls
//Return to the previous directorycd ..
//Enter 1 directorycd 1
//Delete the files in the current directoryrm 
//Return to the previous levelcd ..
//Delete the directory named 1rmdir 1
// Check whether the delete operation is successfulls
//View file permission informationla -al
//The file permissions for modification are the highestchomd 777 
// Check whether the file permission information you just modified is successfulla -al
//View the md5 of the filemd5 
//View the mounting device informationmount
//Change the system partition into readable and writable "mount -o [option] devices directory"mount -o remount,rw /dev/block/sda6 /system
// Check whether the modification just now succeedsmount
//View partition list
df
//Uninstall the "/storage/sdcard" partition mountumount /storage/sdcard
// Check whether the uninstall just now is successfuldf
//Enter the contents intoecho 333 &gt;&gt;
echo 222 &gt;&gt;
//View the filecat 
//Stend whether there is any difference between the two filescmp  
//Copy the folder and paste it in the current directory and name itdd if= of=
//Stend whether there is any difference between the two filescmp  
cd
//Create a hard connection file named 2 in directory 2 (because the file already exists in directory 2, otherwise use the "ln 2" command)ln  2/
//Enter into 2 directorycd 2
//View file contentcat 
//Include content in the fileecho &gt;&gt;
//Return to the previous directorycd ..
// Check whether the file content of the connection file is consistent withcat 

2. Information query related commands

Related Commands

Subcommand parameter illustrate
dumpstate - System status information (root permission is required)
Including the current memory information of the phone, CPU information, logcat cache, kenel cache, etc.
adb bugreport contains this information
bugreport - It contains dmesg, dumpstate and dumpsysysy
demsg - kenel's log
logcat More parameters Print log buffer logs
dumpsys meminfo [processName]
activity [processName]
Obtain various service information of the system

2. Obtain system information related commands

Subcommand parameter illustrate
getevent - Get key information
getprop - Get system properties
setprop - Set system properties (root permission is required)
pm - Installation package management, query various information about installation packages
ps - View process information
top -m num Maximum number of displayed numbers
-n num update times
-d num update time between the two
-s col by which column (cpu, vss, rss, thr)
-tShow thread information instead of process
-h Show Help Document
Get CPU usage
procrank - Query the memory consumption of each process (root permission is required)
wm size Get screen resolution

3. Command usage example

//Output system status information to F:\test\. Since root permission is required, the output of mobile phones without root is emptyadb shell dumptate &gt;F:\test\
//Output the past system status and log. Generally, if the log is not crawled during operation, use this command to view it if there is a problem.adb shell bugreport &gt;F:\test\
//Output kernel informationadb shell dmesg
//Output the current buffer log and save itadb shell logcat &gt;F:\test\
//Output memory informationadb shell dumpsys meminfo
//Output current CPU usage informationadb shell dumpsys cpuinfo
//Output current activity usage informationadb shell dumpsys activity
//Equivalent to filtering, only find the usage information of the activity named "mF"adb shell dumpsys activity | find "mF"
//Get key information. If the phone does not have key information, you will be prompted first by the device information represented by the ID of each device. The key will be refreshed in real time during the key press.adb shell getevent
//Get system propertiesadb shell getprop
//View pm help informationadb shell pm
//View the installation package list in the mobile phoneadb shell pm list packages
//View the current mobile phone process informationadb shell ps
//Get CPU usage, view it only once, and do not refresh it in real timeadb shell top -n 1
//Get the usage of the top ten CPUs, only view them once, and do not refresh them in real timeadb shell top -n 1 -m 10
//Query the memory consumption of each processadb shell procrank
//Inquiry of the memory usage of a package in detailadb shell dumpsys meminfo packageName

3. Operate mobile phone related commands

1. Related Commands

Subcommand parameter illustrate
bmgr [backup | restore | list | transport | run]
bmgr backup PACKAGE
bmgr restore
......
Data backup and restore
kill kill [-s signame | -signu | -signame]{job | pid | pgrp}...
kill -l [exit_status...]
End the process
reboot none Restart your phone
svc power control power management
data controls data connection
Control wifi management
Control USB status
Control power, network, USB
wipe wipe system | data | all Erase partition and restore factory settings
am am [subcommand] [options]
am start
......
antivyty manager
Used to enable applications, broadcasts, services and other functions

2. Command usage example

//Query the installed package name listadb shell pm list package
//Use the monkey command for the packageadb shell monkey -p  --throttle 200 50000
//Find monkey process informationadb shell ps | find "monkey"
//Kill the monkey process, the number in the example is the monkey's PID process numberadb shell kill 23770
//Restart the phoneadb shell reboot
//Open the svc help interfaceadb shell svc
//Query wifi operation helpadb shell svc wifi
//Close wifiadb shell svc wifi disable
//Open wifi
adb shell svc wifi enable
// Erase data, that is, restore the factory settingsadb shell wipe data
//Specify the activity information of querying "mF"adb shell dumpsys activity | find "mF"
//Start the specified activityadb shell am start -n /.BrowserActivyty
//View the help information of the am commandadb shell am

4. Test purpose related commands

1. Test information related commands

Subcommand parameter illustrate
iftop iftop [-r repeats] [-d delay] List network transmission packet situation
Monkey Monkey [options] count Execute the Monkey command
netstat - Display various network-related information
ping ping [option] ipv4 Internet packet detector, program for testing network connections
ping6 ping6 [option] ipv6 Internet packet detector, program for testing network connections
screenrecord screenrecord [options] < filename > Screen recording (only supports devices with Android 4.4 or above)
screencap [-hp] [-d display-id] [FILENAME]
-p file saving path
Screenshot
uiautomator uiautomator [options] Execute uiautomator script

Command usage example:

//Enter interactive modeadb shell
//List the network transmission packet situationiftop
//Show various network related informationnetstat
//Real-time viewing of network connectionsping 
//Real-time viewing of network connectionsping6 
//Screen recording, the saving path is /mnt/sdcard/1.mp4. It should be noted that screen recording only supports devices above android4.4 to stop recording using ctrl+c using sdcard/1.mp4.screenrecord /mnt/sdcard/1.mp4
//Export 1.mp4 under the sd card path to F disk (exit interactive mode first)adb pull /mnt/sdcard/1.mp4 f:\
//screenshotscreencap /mnt/sdcard/

2. Enter information command

1)input

Function: Simulate the input of hardware devices
Format: input []  [...]
parameter:

  • test(Defalt;touchscreen)
  • keyevent [--longpress] ...(Default:keyboard)
  • tap (Default:touchscreen)
  • swipe [duration(ms)] (Default:touchscreen)
  • press (Default:trackball)
  • roll (Default:trackball)

2) Command usage example

//Enter interactive modeadb shell
//Input text 123456input text 123456
//Use keycode num input, the keycode table can be queried on Baiduinput keyevent 7
//Enter 1 using keycode nameinput keyevent KEYCODE_1
//Press space key using keycode nameinput keyevent KEYCODE_HOME
//Click coordinate 367 1277input tap 367 1277
//Swipe from (1024, 945) to (134, 968) within 200 millisecondsinput swipe 1024 945 134 968 200

This is the end of this article about detailed explanation of commonly used adb shell commands. For more related adb shell commands, please search for my previous articles or continue browsing the related articles below. I hope everyone will support me in the future!