Small knowledge, big challenge! This article is participating in the creation activity of “Essential Tips for Programmers”

Android system itself belongs to the simplified version of Linux, some functions are missing, and many Linux commands cannot be used. Here we summarize several commands that can be used to facilitate shell command operation

First of all,

1. Use ADB to enter the shell middle

Adb -s Device name shellCopy the code

2. Change the read/write permission. Otherwise, commands cannot be performed

mount -o remount ,rw /
Copy the code

The available commands

  1. ping
ping baidu.com
Copy the code
  1. cat
Cat xxx. TXT // View the file. Cat /proc/cpuinfo// View the CPU informationCopy the code
  1. curl
Curl -o curl -o curlCopy the code
  1. mv
mv ./a.txt .. // / move the fileCopy the code
  1. date
Date // View the current timeCopy the code
  1. top
Top // Displays the current system resource consumptionCopy the code
  1. The Dalvik VM is called to execute the APK file

Creating a Java file

public class Foo{
    public static void main(String [] args){
            System.out.println("Hello, world!haha");
        }
}
Copy the code

Convert.java to a.class file

dx --dex --output=foo.apk Foo.class
Copy the code

Install it on the device

adb push foo.apk /sdcard/
Copy the code

Call Dalvik VM to execute foo.apk

adb shell

dalvikvm -cp /sdcard/foo.apk Foo
Copy the code

  1. View the current Activity information
Adb shell Dumpsys Activity Top // Can quickly locate the current activity pathCopy the code
  1. Command line to start debugging mode
adb shell am start -D -n packagename/ MainActivity
Copy the code
  1. Obtaining process PID
ps | grep packagename
Copy the code
  1. Establishing port Forwarding
adb forward tcp:8700 jdwp:pid
Copy the code
  1. Viewing Device Parameters
Getprop # This command can view all device information including CPU network model, etcCopy the code
  1. View available commands on the device
CD system/bin # You can view all available commands in this directoryCopy the code