Modern smartphones based on Android are powerful pocket computers that hide a full-fledged core under a graphical interface Linux. For most users, interaction with the device is limited to touching the screen and voice commands, but the true power of the system is revealed when accessing the command line. Terminal allows you to execute complex scripts, manage processes, edit system files and conduct deep network diagnostics without installing unnecessary applications with a graphical shell.

Using a terminal emulator requires some preparation and understanding of the basic principles of the operating system. Errors when entering commands can lead to unstable operation of the device or loss of data, so this tool should be treated with due respect. In this article, we will look at how to install a popular application Termux or a classic Terminal Emulator, master the basic commands and learn how to use them to solve practical administration problems.

Whether you are a developer, a modding enthusiast, or just a curious user, understanding the command line will open up new ones for you horizons in managing your gadget. We will look at both basic navigation operations and advanced techniques for working with superuser rights.

Installing and initial configuration of the emulator

The first step towards mastering the command line is selecting and installing suitable software. For a long time, the application Android Terminal Emulator from Jack Palais was considered the de facto standard, but the project was closed and no longer receives updates. Today, the most relevant and functional solution is Termux, which is not just an emulator, but a full-fledged Linux environment without the need to obtain root access at the initial stage.

For installation, it is recommended to use the official store F-Droid, since the version in the Google Play Store is often outdated due to store policy restrictions on access to system APIs. After installing the application, you need to launch it and wait for the package update process to complete. This is a critical step, since the base repositories must be synchronized with the development servers for the package manager to work correctly pkg or apt.

During the first setup, the system will ask for permission to access the device storage. If you plan to work with files outside the application's isolated sandbox, you must confirm this action by entering the command termux-setup-storage. After confirmation, a symbolic link will appear in the root home directory storage, providing access to the internal storage and SD card.

โš ๏ธ Warning: Granting file permissions gives the application the ability to change any data in the shared memory. Use this function only with trusted scripts and do not run unknown code from the Internet without prior analysis.

โ˜‘๏ธ Initial setup of Termux

Done: 0 / 4

Basic navigation and file management commands

The command line interface may seem intimidating to beginners due to the lack of buttons and menus, but all work is based on a logical system of text commands. The basis of interaction is the file system, and the first thing you need to master is navigating through directories and viewing their contents. Unlike Windows, where paths are often written using a backslash, in the Linux environment of Android, a forward slash is used /, and the user's root directory is indicated by a tilde ~.

To view a list of files in the current folder, a utility is used ls. Adding a key -la will allow you to see hidden files (starting with a dot) and detailed information about access rights, owner and size. Moving between folders is carried out by the command cd (change directory), and returning to the home directory is performed by simply entering cd without arguments or using cd ~.

Creating, copying and deleting files is also performed using text commands, which allows you to automate these processes through scripts. For example, creating an empty file is done through touch filename.txt, and creating a directory through mkdir foldername.

  • ๐Ÿ“‚ ls -R โ€” recursive output of a list of all files in the current folder and all nested subdirectories.
  • ๐Ÿ“ cat filename โ€” quick output of the contents of a text file directly to the console without opening the editor.
  • ๐Ÿ” grep "text" file โ€” search for a specific line of text inside file, indispensable for analyzing logs.
  • ๐Ÿ—‘๏ธ rm -rf folder - forced deletion of a folder with all its contents requires maximum caution.
Hidden files in Android

In the Android system, many application configuration files are hidden from normal viewing in file managers. In the terminal, they are visible when using the -a flag, since their names begin with a dot (for example, .bashrc or .termux). These files often contain important environment settings and command aliases.

Working with access rights and Root mode

The security of the Android operating system is built on isolating applications and delineating access rights. By default, the terminal emulator runs as a normal user with limited privileges, which protects system partitions from accidental damage. However, to perform some tasks, such as changing system network settings or modifying files in a directory /system, superuser rights are required (root).

If your device has an unlocked bootloader and installed MagmaSU or KSU, you can get extended rights inside the terminal. For this you can use command su. When you first start, the system will ask for confirmation through the root manager pop-up window. If the device is not rooted, the command su will return a "permission denied" error, and you will remain within the user sandbox.

Working in .root mode requires extreme concentration. One incorrect command, for example, accidentally deleting a critical library. in /system/lib, can lead to a bricked device or an endless reboot (bootloop). Always check the file path before performing destructive operations, especially when you are in privileged mode.

Command Description of action Required Root Risk level
chmod 777 file Full rights to read, write and execute Frequent Average
chown user:group file Change file owner and group Yes High
mount -o remount,rw /system Remounting the system partition in recording mode Yes Critical
pm disable package Disable the system application without uninstalling No (ADB) Medium
โš ๏ธ Attention: Changing access rights to executable files in system directories may violate the integrity of Verified Boot. This may result in the device stopping booting or some banking applications refusing to work due to SafetyNet/Play Integrity protection.
๐Ÿ“Š Does your device have root access?
Yes, full access
No, I work in the sandbox
I plan to get it
I donโ€™t know what it is

Network diagnostics and ping tools

One of the most popular terminal functions on mobile devices is advanced network diagnostics. Standard Android settings provide only basic information about Wi-Fi status, while the command line allows for in-depth connection analysis, route tracing, and port scanning. This is especially useful for system administrators and cybersecurity specialists working in the field. conditions.

The basic tool for checking the availability of a host is the command ping. It sends ICMP packets to the specified IP address or domain name and measures the response time. Unlike Windows, where the default ping is four packets, in the Linux Android environment the command will run endlessly until you interrupt it by pressing a key combination. Ctrl + C (on the touch screen there is usually a special ESC or CTRL button on the virtual keyboard).

For a more complex analysis of the route of packets, use the utility traceroute or tracepathIt shows each intermediate node (hop) between your smartphone and the target server, which helps. identify where in the network there is delay or data loss. Also a powerful tool is netstat or its modern replacement ss, which allows you to see all active network connections and listening ports on the device.

Device owners with superuser rights can use the package Nmap to scan the ports of other devices on the local network. This allows you to identify open services, vulnerabilities and unauthorized connections. However, using such tools on other people's networks without permission can be regarded as a hacking attempt.

  • ๐ŸŒ ping -c 4 google.com โ€” sending exactly 4 packets to check the availability of the Google server.
  • ๐Ÿ›ฃ๏ธ tracepath ya.ru โ€” building a route to the Yandex server indicating delays on each node.
  • ๐Ÿ”Œ netstat -tuln โ€” displaying all TCP and UDP listeners ports with numeric addresses.
  • ๐Ÿ“ก ifconfig (or ip addr) - detailed information about network interfaces, IP addresses and MAC addresses.
๐Ÿ’ก

To conveniently enter special characters, such as a dash or slash, configure an additional keyboard panel in the Termux settings. This will speed up the input of network commands and file paths.

Installing packages and managing the software environment

The uniqueness of the modern emulator Termux lies in the presence of its own package manager, which turns the smartphone into a full-fledged developer workstation. You can install compilers (GCC, Clang), programming language interpreters (Python, Ruby, Node.js, PHP), text editors (Vim, Nano, Emacs) and even graphical applications via X11. The package ecosystem is constantly updated and includes thousands of utilities from the Linux world.

The software installation process is as simplified as possible. To search for the required package, use the command pkg search name, and to install - pkg install name. Manager automatically resolves dependencies by downloading all necessary libraries. It is recommended to regularly update the list of repositories and installed packages with the command pkg upgradeto receive security fixes and new features.

When working with programming languages, it is important to consider the processor architecture of your device (usually aarch64 for modern smartphones). Most popular packages are optimized for this architecture and run natively, providing high performance. However, some old or specific utilities may be unavailable or require emulation, which reduces the speed.

Packages in Termux are installed in an isolated directory /data/data/com.termux/files/usrrather than in the system partition, which avoids conflicts with the main Android operating system.

If you plan to use the terminal for development, you should pay attention to installation Git for version control and SSH for remote connection to servers. This allows you to write code on your phone, commit changes to the repository and deploy projects directly from your mobile device, turning your smartphone into a pocket server.

Alternative repositories

In addition to the main repository, there are unofficial communities (termux-x11, root-repo) that provide access to additional packages, including graphical desktop environments. Connecting such repositories requires editing configuration files in the directory /data/data/com.termux/files/usr/etc/apt/sources.list.d.

Automation of tasks and writing scripts

The true power of the terminal is revealed when automating routine operations. By writing a small script in Bash or Python, you can force the phone to perform complex sequences of actions according to a schedule or when certain events occur. This could be automatic backup of important files, monitoring battery charge, scraping web pages or sending notifications.

Scripts are text files containing a sequence of commands. To create them, you can use the built-in editor nano or vim. After writing the code, the file must be given permission to execute using the command chmod +x scriptname.sh. Launch is carried out by entering the path to the file, for example, ./scriptname.sh.

To execute scripts on a schedule in the Termux environment, there is a daemon cronthat can be installed through the package manager. By setting up the file crontab, you can specify the exact time and date for your automations to run. This allows you to implement functionality similar to tasks in the Windows scheduler or cron in Linux server systems, directly on a mobile device.

  • ๐Ÿค– Scripts allow you to combine several commands into one logical block with conditions and loops.
  • โฐ Automation via cron works even in the background if the application is allowed to run in background.
  • ๐Ÿ’พ Using scripts, you can easily create backup archives and send them to cloud storage.
  • ๐Ÿ”” Integration with the Android notification API allows scripts to send reports on work performed to the notification curtain.
โš ๏ธ Attention: Interfaces and commands may vary slightly depending on the Android version and the specific emulator build. If any command does not work, check the official project documentation on GitHub or Wiki, as packages are updated regardless of the operating system version.
๐Ÿ’ก

Automation through scripts turns a smartphone from a content consumption device into a powerful tool for solving specific engineering and administrative tasks.

Frequently asked questions (FAQ)

Is it safe to use the terminal on a regular smartphone without Root?

Yes, it is absolutely safe. In non-superuser mode, the application runs in an isolated sandbox and has access only to its own files and data that you have explicitly given permission to access (for example, photos or music). It cannot damage Android system files or device firmware.

Is it possible to hack a neighbor's Wi-Fi through the terminal on the phone?

No, this is impossible using standard means. To intercept packets and carry out attacks on Wi-Fi networks (for example, deauth attacks), a network adapter that supports packet monitoring and injection mode is required. Built-in Wi-Fi modules in 99% of smartphones do not support these functions at the driver level, even with root access.

How can I return all the terminal settings to factory settings if I broke something?

The easiest way is to clear application data in the Android settings. Go to Settings โ†’ Applications โ†’ Termux โ†’ Storage โ†’ Clear data. This will remove all installed packages, scripts and configuration files, returning the application to its post-installation state. Your personal files in the phone's general memory will not be affected.

Why does the sudo command not work, even if I entered it?

Command sudo is intended for temporary elevation of rights in systems where you log in as a normal user, but know the administrator password. The default Android terminal does not have a root user configured with a password. To obtain full rights, use the command su, and it will only work if root access have already been obtained on the device and the appropriate manager (Magisk/KSU) is installed.

Is it possible to run a full-fledged desktop Linux (Ubuntu, Kali) on Android?

Yes, this is possible using chroot or proot (PRoot). There are ready-made scripts and applications (for example, Andronix or installation scripts in Termux itself) that allow you to deploy a full-fledged Linux distribution on top of Android. You will be able to run graphical applications by connecting via a VNC client, although performance will depend on the power of the phone's processor.