Commands in Android Terminal Emulator

F If you have an Android smartphone and are familiar with Linux, you probably wondered at least once how to use the terminal in Android. As you know, the Android operating system is based on the Linux kernel, which means that there is a command shell and many standard Linux commands are available in it. By default, there is no standard terminal utility in Android. You can access it in several ways:

  • the first is to download the Android Terminal Emulator app from GooglePlay.
  • the second is to connect to smartphone from computer using adb debugger.

But our article is not about that, today's topic: commands in the Aandroid Terminal Emulator, or more precisely, the commands of the Android terminal.

There are many articles on this topic on the Internet, but in all of them something is missing, a couple of specific commands are described and that's all, but I want a complete list, including Linux commands, then I decided to write this article. I am not saying that I will describe all the commands, but I will try to cover the majority. This is just a short description of some of the Android commands I will explain in more detail in the following articles, and you can find detailed information on Linux commands on the Internet.

Now about the notation - some commands require root rights, I will put the @ sign in front of them.

Let's start. Terminal commands are nothing more than small console utilities, most of the system utilities are located in the / system / bin folder and a few more in / vendor / bin. We will not touch those in vendor. To make it easier to arrange all the commands alphabetically.

adb - Android debugger. Since Android is still Linux, you can connect other devices, including smartphones, to it via USB, adb allows you to control them and gives access to their terminal. the description of its commands and capabilities stretches for a whole article, I will describe everything in one of the following articles.

am - Manager of windows (Action Manager), with it you can start and stop any application or service. For example, launching the setup application:

am start -n com.android.settings / .Settings

badblocks - checking the flash drive for bad sectors:

The result can be written to a file:

badblocks / dev / block / mmcblk0\u003e / sdcard / badblocks

or to display:

badblocks -v / dev / block / mmcblk0

bmgr - Android backup management.

cat - console utility for viewing file contents.

cat /sdcard/text.txt

chmod - similar to Linux command, changes file permissions, only octal recording format is available.

For example, give all rights (read, write, execute):

chmod 777 / sdcard / file

chown - changes the owner of a file in Linux, For example:

chown root / sdcard / file

cmp - compares two files

cmp / sdcard / file1 / sdcard / file2

cp - copies the file from the source (parameter 1) to the receiver (parameter 2).

cp / sdcard / file1 / sdcard1 /

date - show the current date in the system.

Sat Nov 14 13:44:56 EET 2015

dd - create a disk image, Parameters if \u003d disk device file, of \u003d file to write

For instance:

dd / dev / block / mmcblk0 /sdcard/img.iso

An image of the mmcblk0 flash drive will be created.

df - analysis of free disk space. For instance:

df -h / dev / block / mmcblk1

Filesystem Size Used Free Blksize
/ mnt / secure 484.5M 0.0K 484.5M 4096
/ mnt / asec 484.5M 0.0K 484.5M 4096
/ mnt / obb 484.5M 0.0K 484.5M 4096
/ system 1.4G 971.7M 435.8M 4096

dmesg - viewing the kernel message log.

du - view the file size.

du / sdcard / file1

@ ext4_resize resizing an ext4 partition.

@ fsck_msdos - checking the flash drive for errors.

fsck_msdos / dev / block / mmcblk1p1

grep - utility for filtering text. For example, display only lines containing terminal:

cat ~ / sdcard / file | grep terminal

@ ifconfig - viewing and managing network devices. For example, viewing wifi card information:

Or disabling wifi:

ifconfig wlan0 down

You can find out the list of network devices with the command:

ls / sys / class / net

iptables - managing the iptables firewall settings, this is a very extensive topic that we will not touch on.

kill - kill the process by its PID.

You can use the ps utility to find out the pid.

ln / sdcard / file / sdcard / file2

log - write a line to the system log.

logcut - viewing the system log in real time.

ls - viewing the list of files and folders in the directory:

lsmod - view loaded kernel modules

lsof - viewing files open in the system.

make_ext4fs - format the flash drive to the ext4 file system

md5 / sdcard / filename

mkdir - create a folder in the current directory.

mkdir folder_name

make2fs - format the flash drive to the ext2 file system

mount - mount a disk, image or folder. For instance:

mount -t ext2 / dev / block / mmcblk1p1 / mnt / sdcard

mv - move file, similar to cp

netcfg - viewing information about network connections.

notify - a utility for tracking changes in the file system using the inotify kernel subsystem.

ping - a well-known utility for checking the availability of a network node.

pm - android package manager, allows you to install, uninstall and view installed packages.

ps - View all running processes and information about them.

USER PID PPID VSIZE RSS WCHAN PC NAME
root 1 0 1000 848 c0106ef8 0001bfb4 S / init
root 2 0 0 0 c006e038 00000000 S kthreadd
root 3 2 0 0 c0057a54 00000000 S ksoftirqd / 0

reboot - restart the smartphone from the console.

resize2fs - similar to resize_ext4, only for ext2

rm - delete a file.

rmdir - delete a folder.

rmdir / sdcard / dirname

rmmod - unload the kernel module.

rmmod module_name

route - management of the routing table.

touch - create an empty file.

touch / sdcard / file

top - an interactive version of the list of running processes.

@ screenshot - take a screenshot.

screenshot /sdcard/screenshot.png

shutdown - turn off the smartphone.

service - service management. For example, see the list of running services:

These were all the commands I found, the list will be updated if possible.

about the author

Founder and site administrator, I am fond of open source software and the Linux operating system. I am currently using Ubuntu as my main OS. Besides Linux, I am interested in everything related to information technology and modern science.

Qute - fast and powerful terminal.
The command line, or console, is a type of text-based interface in which interaction with a computer is carried out using commands. There are not so few fans of this way of communicating with systems, and the reasons are obvious. This is the ease of automation, calling any command with a small number of clicks, the lack of interface details, and much more. The Qute application will help you test the capabilities of the console on your smartphone by executing many terminal commands and bin-files.

The user will not need to waste time authorizing using social media accounts or creating a new account. A few moments after clicking on the application icon, the console and keyboard for entering commands will appear on the screen. It is likely that before directly using the capabilities of Qute, the owner of the smartphone will want to explore all the nooks and crannies of its menu. In this case, in the upper left corner of the display there is a button for switching between windows, and in the upper right there are three controls at once.

First of all, this is a list of commands, which you can edit yourself. When adding a command, the user needs to enter its name and the command itself with arguments. In addition, here you can create a shortcut or program the launch of a command when the device boots.

The two remaining buttons are for new window creation and settings. Usually, users neglect to familiarize themselves with the settings menu, it is not recommended to do this in Qute. The fact is that the settings contain a help menu, which lists all the basic commands and variables with which the application works. After studying them, you can safely proceed to work with the program.

As you enter commands, the user will be prompted for arguments, which greatly simplifies the work. The application supports most of the popular PC commands. This includes ping, netstat, trace, cd, mkdir, and more. Other benefits include support for rooted devices. Qute will be able to provide the owner of the device with full access to all the capabilities of the system terminal. Accordingly, control over the system will be exclusively in your hands.

Features::

  • Bash script editor
  • Running terminal commands and available bin files
  • Creating your own command list
  • Automatic command completion
  • Support for rooted devices
  • Download program Qute: Command line for Android you can follow the link below.

    Developer: D.D.M.
    Platform: Android 4.0 and above
    Interface language: Russian (RUS)
    Condition: Free (Free)
    Root: Not needed



    What interesting commands are there for the terminal emulator?

    Answers (2)

    1. Terminal emulator is an android application through which you can use commands to control the system and make changes to it. This mechanism is based on the fact that the android system includes the linux kernel.

      On the computer, using the command line and utilities, the system is configured and additional modules are connected. Android has inherited many similar capabilities that can be applied for different purposes.

      That is, there are binary files that interact directly with the hardware. Each such file corresponds to a text command that runs through a terminal emulator.

      Before you start working with the command line, it should be noted that the greatest scope for modifications will be after rooting the android device.

      In addition, you should install busybox - a binary file that will allow you to use more commands, since the built-in ones are often not enough. To install it you need:

      • download from Play Market BusyBox;
      • open and grant him superuser rights;
      • be sure to wait while the application scans the device;
      • click the "install busybox" button;
      • determine the location "/ system / xbin";
      • press "ok".

      After that, you can start installing the terminal on the android and working with it. For this:

      Other commands may take a long time to complete and a white cursor will appear. If a mistake was made while writing, the message "/ system / bin / sh: kv: not found" and a prompt for input will appear. This message indicates that the kv command was not found among those available.

      The terminal is closed by clicking on the cross in the upper right corner, then a window will appear in which we click "ok".

    2. There are a lot of commands, to see them all you need to write "busybox" without quotes. In principle, the description of each can be viewed in the terminal itself, for this you need to enter the command we want to know about and "-help". Information will appear, but in English. When working with the terminal, you should take into account some peculiarities:

      • the path to files and folders must be written completely after the commands, for example, rm / storage / sdcard0 / download / file;
        there should be no errors and extra spaces;
      • the command is launched by the "enter" button, that is, entered and pressed.

      Here are the most popular android terminal commands:

      • cat - reading content, cp - copying, rm - deleting a file, rmdir - deleting a folder, touch - creating a file, mkdir - creating a folder, - after these commands, enter the path to the desired object or place;
      • mv - move, cp - copy, - first write the path to a file or folder and then to a new location;
      • ls - displays content;
      • cd - navigates to the desired directory;
      • pwd - shows the full path to the used folder;
      • date - displays the real date;
      • df - shows the size of objects in the specified folder;
      • du - prints the size of the file;
        pm install - installs the program from the apk file;
      • pm list packages - shows packages-files of installed applications;
      • service list - displays a list of running processes;
      • pm uninstall - uninstalls the application, while you must specify the path / data / app / file name, which can be found with the pm list packages command;
      • ln - creates a symbolic link to a file, the syntax is the same as cp.

      It is necessary to be very careful to execute the commands of the terminal emulator, which I will talk about further, since they are used to modify the system and, if used incorrectly, can seriously harm the device:

      • su - provides full access to the system on rooted devices, after entering it, the prompt line will look like this " [email protected]:/ #»;
      • chown and chgrp, the first for changing the owner, the second for the groups that are specified after the command, and then write the file name;
      • chmod - utility for changing the file's rights, the syntax is the same as the previous one - first the rights, then the file;
      • insmod and rmmod use the first to connect modules to the kernel, the second to remove, these commands are best used only for advanced users;
      • kill - stops the process by its identifier, which can be found using the ps utility - it displays information about all activities;
      • mount, umount are intended for mounting and unmounting file systems and partitions, use only after a detailed study of the system.

      Special commands that are executed by the Android terminal emulator:

      • reboot - used after the su command to reboot the device;
      • exit - closes the terminal, you can also exit the administrator through it.

      That is, we used su for utilities that require root rights and further, so as not to accidentally change something, enter exit, and the prompt will again become like “ [email protected]:/ $».

      There is another unusual utility dd - it copies one file or section to another by bytes. She has the following syntax:

      dd if \u003d / dev / block / platform / mmcblk0p1 of \u003d / storage / external_SD / image
      if \u003d device to copy from of \u003d file to copy to. This command will create an image of the mmcblk0p1 partition.
      It has 2 more parameters - count \u003d the fragment to which the new file will be written, bs \u003d the size of the fragments in bytes. For example, the command dd if \u003d / storage / sdcard0 / file1 of \u003d / storage / external_SD / file2 bs \u003d 500 count \u003d 7 will copy 7 pieces of 500 bytes from file1 to file2.

    Name_device: / $
    Where
    Name_device: / this is the name of your smartphone (tablet)

    su - the su command gives you Root rights, administrator rights, that is, you can do everything with the device after this command (not before), you also need to get root on your android device.

    Note: Before executing the Su command, you are a guest.
    Name_device: / $
    The $ symbol means that you are a guest (i.e. you cannot do anything)
    Name_device: / #
    # Means you are Root
    Example
    Name_device: / $ su
    Name_device: / #

    pwd - shows the current directory you are in.

    ls - the command shows what is in the current directory, namely files and directories.
    Example
    Name_device: / # ls
    system
    data
    mnt
    bin
    etc...

    ls -a - the command shows what is in the current directory, namely files and directories, but with hidden files.
    Note: Hidden files, unlike Windows, look like .Name (period and file name)

    clear - clear the terminal screen.

    cd - command to go to any directory (directory).
    Example
    Name_device: / # cd system
    Name_device: / system #
    Note: Directory or Directory means Folder
    cd .. - go to the directory one level higher

    mkdir - the command creates a directory (folder).
    Example
    Name_device: / sdcard # mkdir android
    Note: Folder Name and name are two different folders

    rm - deletes the file.

    rm -r deletes a directory (Note: if you do not specify the –r parameter, it will generate an error about the impossibility to delete a directory).
    Example
    Name_device: / sdcard # rm -r dom

    rm -rf - deletes a file and does not display messages if there is no such file or no permissions to write to it rm -rf - deletes folders without displaying messages.

    cp - copies the file.

    cp -r copies a directory.

    mv - renames the file.
    Example
    Name_device: / sdcard # mv android ANDROID

    touch - creating an empty file.

    cat - displays the text in the file.
    Example
    Name_device: / sdcard # cat skazka

    tac - displays the text in the file in reverse order (1 line last, last first).
    Example
    Name_device: / sdcard # tac skazka
    Note: if you see a # sign in front of the line, then the parameter is not processed

    ps - displays your currently active processes.

    mount - mounts (Connect).

    umount - will unmount.

    date - displays the current date and time.

    cal - displays the calendar of the current month.

    uptime - shows how long the operating system has been running.

    df - show information about disk usage.

    free - used memory and swap.

    free -m - total volume, used volume and free memory in Mb.

    du - how much space your data takes

    halt - quick and correct system shutdown

    chmod - setting access rights



    There are many tools for working with a USB or Wi-Fi connected smartphone. Advanced tools allow you to move files, install and uninstall software, view contacts, take screenshots, and even send SMS, but no graphical tool comes close to the power that an Android console can provide. In this article we will talk about ADB (Android Debug Bridge) - a standard tool for debugging and working with the Android console from a computer.

    The commands described in the article can be executed directly on the device by downloading a terminal emulator from the market, but it is more convenient to do this, of course, from a computer via adb.

    ADB Basics

    To start working with ADB, you must activate it on the device and install the adb utility and drivers on the computer. The first task is performed by enabling "USB Debugging" in the "For Developers" settings item (if this item is hidden, press seven times on the build number in the "About phone" menu).

    To install ADB on your computer, download the Adb Kit and unpack it into any folder (I recommend using the folder names without Russian characters). We also download and install the ADB drivers.

    You need to work with adb from the command line. Press Win + R and enter cmd, then go to the folder that contains adb. For my folder, the command would be:

    Cd \\ android

    In order not to do all these manipulations every time, you can add the desired folder to the Path variable. To do this, go to Control Panel -\u003e System -\u003e Advanced System Settings -\u003e Environment Variables, find the Path variable and add the path to the folder with adb at the end of the line, separated by semicolons. Now after starting the console, you can immediately enter the necessary commands.

    Let's check our connection to the phone using the following command (it should display a list of connected devices):

    Adb devices

    You can work with ADB via Wi-Fi. This requires root rights and the WiFi ADB app. We launch the application, press the switch and connect to the smartphone using the connect command and the IP address shown by the application:

    INFO

    You can copy the console output after selecting it with the mouse, as well as paste the copied command or file name into the console with the right mouse button. Included in console properties.

    Installing programs

    ADB can be used to install applications without having to copy them to a smartphone. It is enough to execute the following command:

    Adb install d: /downloads/file_name.apk

    Additional keys can also be added to the command. Will be useful -e - reinstall the application while saving the data and -d - install a version less than the current one.

    You can also uninstall programs, but for this you need to know the name of the package (how to find out, I'll tell you a little later). Using the Angry Birds Seasons example, the team will look like this:

    Adb uninstall com.rovio.angrybirdsseasons

    Application backup

    Android has built-in backup functions that can also be started using the command line. To do this, use the adb backup command and a set of options:

    Adb backup [options]<приложения>

    • -f specifies the name of the file to be created and its location on the computer. If the key is missing, the backup.ab file will be created in the current directory;
    • -apk | -noapk indicates whether to include only application data in the backup or the .apk itself (by default it does not);
    • -obb | -noobb specifies whether to include in the backup .obb extensions for applications (does not include by default);
    • -shared | -noshared specifies whether to include the contents of the application on the SD card in the backup (by default it does not);
    • -all indicates the need to backup all installed applications;
    • -system | -nosystem indicates whether to include system applications in the backup (by default it includes);
    • - a list of packages for backup.

    If we want to create a backup of all non-system progs, including .apk ourselves, to a specific location, then the command will look like this:

    Adb backup -f c: \\ android \\ backup.ab -apk -all -nosystem

    After entering, you must confirm the start of the backup on the device itself. To restore the resulting backup, you need to run the appropriate command:

    Adb restore c: \\ android \\ backup.ab

    Console in console

    Along with the aforementioned console, which is a DOS console for Windows, Android has its own. She is called through adb shell and is essentially a standard Linux console, but with an incomplete set of commands, which can be extended by installing BusyBox from the market. There are two ways to use this console. In interactive mode, it is started by the command

    Adb shell

    The $ sign appears in the console (hereinafter, this sign will mean the need to enter the preliminary adb shell command), and after that you can enter a series of commands, getting after each response. The second way - if you need to enter only one command, you can write it in a row behind the adb shell.

    The shell uses standard commands for copying, moving and deleting files: cp, mv and rm... You can change directories ( cd) and watch their contents ( ls). In addition to the standard Linux commands, which you can learn about from any reference book, Android has several of its own specialized tools, but to use some of them, you will have to get root rights on your smartphone, and after starting the console, run the su command:

    Adb shell su

    This should be done if, in response to a command, you see a line similar to "access denied" or "are you root?". If successful, the $ sign will change to #.



    Taking a screenshot

    Done in one line:

    Adb shell screencap /sdcard/screen.png

    After that, the picture must be pulled out of the device with the command adb pull:

    Adb pull /sdcard/screen.png

    In recovery, a screenshot can be made with the following command:

    Adb pull / dev / graphics / fb0

    Then you need to convert the fb0 file to a normal image using FFmpeg, which you need to download and put in the adb folder. The extension must be installed on your device:

    Ffmpeg -f rawvideo -pix_fmt rgb32 -s 1080x1920 -i fb0 fb0.png

    Recording video on the device screen

    adb shell screenrecord --size 1280x720 --bit-rate 6000000 --time-limit 20 --verbose /sdcard/video.mp4

    This command will start recording video with a resolution of 1280 x 720 (if you do not specify, then the native screen resolution of the device will be used), with a bitrate of 6 Mbps, a length of 20 seconds (if you do not specify, then the maximum value will be set to 180 seconds), with display logs in the console. The recorded video will be located in / sdcard (video.mp4 file).

    INFO

    All launched from the console and in adb shell processes that take some time to complete can be interrupted by pressing Ctrl + C. Exit the shell and return to normal adb commands - Ctrl + D.

    Application management

    There are two commands used to manage applications: pm (package manager) - package manager and am (activity manager) - activity manager. These commands have a lot of keys that can be viewed on the developer portal. Let's dwell on a few.

    First, let's get a list of applications installed on the device in the form of package names, which will be useful later:

    Continuation is available only to subscribers

    Option 1. Subscribe to "Hacker" to read all materials on the site

    Subscription will allow you to read ALL paid materials on the site within the specified period. We accept payments by bank cards, electronic money and transfers from the accounts of mobile operators.

    Did you like the article? To share with friends: