The Android mobile operating system, being the Linux kernel, provides users with access to a powerful management tool - the command line or terminal. Unlike the usual graphical interface with icons and menus, working through the terminal allows you to perform deep system customization, manage files at the system level and automate routine tasks that are not available through the standard smartphone settings.

Use command shell opens the door to the world of system administration of your pocket device. However, this tool requires caution and an understanding of exactly how the file system and OS process model functions. An incorrectly entered command can lead to data loss or even bricking of the device, so before you start, you need to be clearly aware of the risks.

In this material we will look in detail at how to access the console, what tools you will need to connect to a PC and how to perform basic operations. You will learn the difference between the normal shell and the mode root, and also get a list of vital commands for everyday use and debugging.

Preparing the working environment and tools

Before entering the first commands, you need to prepare the software environment. There are two main scenarios for using the terminal: locally on the device itself and remotely via a computer. To work directly on a smartphone or tablet, you will need a special emulator application that creates a virtual environment for executing Linux commands.

The most popular and functional solution is the application Termux. This is not just an emulator, but a full-fledged Linux environment without the need for superuser rights. Unlike older terminals, which often required rooting, Termux works in an isolated space (sandbox), providing access to the package manager pkg or apt. This allows you to install hundreds of useful utilities, such as git, python, ssh and even full-fledged text editors like vim or nano.

If your goal is to debug the system, install system applications or restore the device after a failure, you will need a combination of a smartphone and a PC. In this case, the key element becomes Android Debug Bridge (ADB). This is a client-server app consisting of three components: a client that sends commands, a daemon (adb daemon) that executes commands on the device, and a server that manages the interaction between them.

๐Ÿ’ก

To work with ADB on your computer, download the official Platform Tools from the Android developers website, and do not use dubious collections of drivers from unknown resources.

For remote connection, make sure that Developer mode is activated on the device. Usually this is a hidden menu that is activated after clicking on the build number seven times in the Settings โ†’ About phonesection. After activation, an item will appear in the new menu USB debugging, which must be switched to the active state.

Establishing a connection and basic navigation

After installing the necessary software The next step is to establish a reliable connection between your computer and your mobile device. The quality of the cable and the correct drivers play a critical role here. Connect your smartphone to your PC via USB port and select the โ€œFile Transferโ€ or โ€œMTPโ€ operating mode in the notification on your phone screen.

Open a command line or terminal on your computer and go to the folder with installed ADB tools. Enter the command to check the visibility of the device:

adb devices

When you connect for the first time, a system window will appear on the smartphone screen asking you to allow debugging from this computer. Be sure to check the box "Always allow from this computer" and click "OK". If in response to the command you see the device serial number and status device, it means the connection was established successfully. Status unauthorized indicates that you have not confirmed the resolution on the gadget screen.

Now let's look at navigation inside the file system. The operating principle here is identical to classic Linux. You are in a specific directory and moving between them. The command pwd will show your current path (print working directory), and ls will display a list of files and folders in the current directory.

  • ๐Ÿ“‚ ls -la โ€”shows hidden files and detailed information about access rights.
  • โžก๏ธ cd /sdcard โ€”goes to the internal memory directory accessible to the user.
  • โฌ†๏ธ cd .. โ€” return to the parent directory (one level higher).
  • ๐Ÿ  cd ~ โ€”quick transition to the current user's home directory.

It is important to understand the structure of Android partitions. The directory /system contains operating system files and is read-only by default. The folder /data stores user data and applications, access to it is often limited without superuser rights. But /sdcard (or /storage/emulated/0) is the very space where you upload photos and music, and it is open for recording.

๐Ÿ“Š Which method of using the terminal do you prefer?
Locally via Termux
Via ADB from a computer
Only for one-time tasks
Never used

Managing files and access rights

One of the most popular capabilities of the terminal is file manipulation where file managers with a graphical interface are powerless. You can copy, move, rename and delete files in batches using masks and regular expressions. This is especially useful when clearing the cache or transferring large amounts of data.

To copy a file, use the command cp, and to move (or rename) - mv. The deletion of files is performed by the command rm. Be extremely careful: there is no trash in the terminal, and the deleted file disappears forever. Using the flag -r (recursively) allows you to delete entire folders along with their contents.

โš ๏ธ Attention: Never use the command rm -rf / or similar variations without fully understanding their operation. This will lead to instant deletion of the entire file system of the device, after which recovery will only be possible through flashing.

In Linux-like systems, which include Android, each file has an owner and a set of access rights. Rights are divided into three categories: read, write, and execute. They can be assigned to the file owner, user group, and everyone else. You can view rights using the flag -l in the command ls.

Changing rights is performed by the command chmod, and changing the owner is performed by the command chown. However, changing these settings for system files requires superuser rights. In normal shell mode, you are limited by the rights of your user and cannot modify protected sections.

Command Description of action Requires Root
cp source dest Copying a file from source to destination No (within the limits of user rights)
mv old new Moving or renaming a file No (within the limits of user rights)
rm file Permanently deleting a file No (within the limits of user rights)
chmod 777 file Granting full rights to all users Yes (for system files)
chown user:group file Changing the owner and group of the file Yes
Numerical designation of access rights

The number 4 means the right to read (read), 2 - to write (write), 1 - to execute (execute). The sum of these numbers gives the final value. For example, 7 (4+2+1) gives full rights, and 5 (4+1) only reads and executes.

Working with superuser rights (Root)

Obtaining privileged access, or root access, turns the user from an ordinary visitor into a full-fledged system administrator. In this mode, almost all restrictions imposed by the manufacturer are removed. You get the opportunity to remove pre-installed system software (bloatware), change the processor frequency, edit system configs and access any memory sections.

To enter superuser mode from a regular shell, use the command su (switch user). If an access rights manager is installed on the device, for example Magisk or SuperSU, a pop-up window will appear on the smartphone screen asking you to grant privileges for the terminal. After confirmation, the command line prompt will change from the symbol $ to #, which signals a transition to root mode.

It is worth noting that having superuser rights not only expands capabilities, but also increases the vulnerability of the system. A malicious app that gains root access can cause irreparable damage. Therefore, it is critical to grant permissions only to trusted applications and understand the essence of each requested command.

Some commands, such as mounting partitions in write mode or changing the boot logo, work exclusively in privileged mode. An attempt to perform them without su will result in a "Permission denied" error.

โš ๏ธ Attention: Obtaining root access often voids the device's warranty and can disrupt the operation of banking applications and services with a high level of protection (Google Pay, Samsung Pay), if you do not use special hiding modules.

System diagnostics and resource monitoring

The terminal is an indispensable tool for diagnosing problems with a smartphone. When the GUI freezes or becomes unstable, the command line allows you to look under the hood and see the real state of resources. You can monitor CPU load, RAM usage and sensor temperatures in real time.

The command top displays a dynamic list of running processes, sorted by resource consumption. It is similar to the task manager in Windows. Pressing the key M will sort processes by memory use, and P by CPU load. This helps to quickly identify a "gluttonous" application that slows down the system.

To obtain detailed information about the state of the battery, network and general statistics of the device, a powerful tool is used dumpsys. This command can output hundreds of lines of technical information. To avoid drowning in data, use filtering. For example, the command dumpsys battery will show the current charge level, connection status and battery temperature.

๐Ÿ’ก

The `top` command allows you to see in real time which process is loading the system, which is critically important when finding the causes of overheating or rapid discharge.

The command pm list packages, which displays a list of all installed packages (applications). By adding a filter, for example pm list packages | grep facebook, you can quickly find the system name of a specific application for its subsequent removal or freezing.

Advanced operations and automation

The capabilities of the terminal are not limited to simple file management. Using scripts and command sequences, you can automate complex use cases. For example, create a script to backup important configs, clear the cache of all applications at once, or switch network modes.

One โ€‹โ€‹of the advanced features is input and output redirection. The symbol > allows you to write the result of the command to a text file. This is convenient for saving error logs or lists of files. For example, the command logcat > error_log.txt will save the system log to a file for later analysis.

To remotely control the device via Wi-Fi, you can use ADB without a cable. First, connect your phone via USB, then run the command adb tcpip 5555. After that, disconnect the cable and connect to the deviceโ€™s IP address: adb connect 192.168.1.XX:5555. This gives complete freedom to move around the room when debugging.

  • ๐Ÿ”„ reboot โ€” safely reboot the device from the terminal.
  • ๐Ÿ”Œ reboot bootloader โ€” reboot into bootloader mode (Fastboot).
  • ๐Ÿ›‘ reboot recovery โ€” enter Recovery Mode.
  • ๐Ÿ“ถ svc wifi enable โ€” turn on Wi-Fi adapter via the command line.

Automation via the terminal opens the way to creating your own utilities. By writing a simple bash script, you can combine several commands into a single app that will be executed on a schedule or at the click of a button. This turns the smartphone into a powerful tool for developers and system administrators.

โš ๏ธ Attention: Interfaces and available commands may vary slightly depending on the version of Android and the manufacturer's shell (MIUI, OneUI, ColorOS). Always check the specification of your model before executing critical system commands.

โ˜‘๏ธ Checking readiness to work with the terminal

Done: 0 / 5
Is it safe to use the terminal on Android for for a regular user?

Using basic commands to navigate and view files is absolutely safe. Risks arise only when executing commands with superuser (root) rights that modify system partitions. If you do not use the command su and do not delete files from folders /system or /data, it is extremely difficult to disable the device.

Do you need to obtain root access to use the terminal?

No, not necessarily. Applications such as Termux work in an isolated user space and provide huge functionality without the need for rooting. Root is needed only for deep intervention in the operation of the operating system, removing system garbage or fine-tuning the kernel.

What to do if the ADB command is not executed and writes โ€œdevice unauthorizedโ€?

This means that a window asking for debugging permission appeared on the smartphone screen, but you did not confirm it or missed it. Disconnect and reconnect the USB cable, unlock your phone screen and click "Allow" in the pop-up dialog. Also check if the "USB Debugging" switch is enabled in the developer settings.

Is it possible to recover a photo deleted through the terminal?

In most cases, no. The command rm removes a link to a file in the file table, marking the space as free. If nothing new was written over this data, recovery is theoretically possible using special utilities for memory analysis, but under conditions of active smartphone operation this is unlikely. Always make backups before mass deleting.

What is the difference between the sh and bash shell in Termux?

sh (Bourne shell) is a basic, minimalistic shell available on the system by default. bash (Bourne Again Shell) is a more advanced version with history support commands, auto-completion, scripts and convenient editing of the input line. Termux bash or zsh are often used by default, which makes the work much more comfortable.