Termux – Run command line tools on your Android phone | | Resource Centre by Reliance Digital
Home > HOW-TOs > Termux – Run command line tools on your Android phone

Termux – Run command line tools on your Android phone




Share This Post

The Android operating system is a very refined piece of software, designed specifically for devices with a touchscreen interface. This makes it easy for anyone to use it, without any prior knowledge of the device or software. While intuitive, there are downsides to this approach too. Most of the software is often only skin deep, making the most of the limited screen space. There are large buttons and menus with only the essential information displayed in the most colourful and flamboyant manner. Another approach to software exists, though it’s made for the geekier folk who like to tinker with software. The command line interface (CLI) is an environment that allows for a world of applications and scripts to be run on a device, offering much more information and functionality, even automation even on a device as tiny as a smartphone. This is our little gateway to the Termux terminal emulator.

Termux gives you access to a Linux prompt enabling you to do a whole range of things. It’s also a good place to learn some Linux commands, and get used to running Linux software on your phone. Termux can be launched like any other app on your phone. However, software that you install on Termux will run only through the command prompt, with no signs of any touch interface, or shortcuts in your app drawer. The onscreen keyboard (or physical keyboard) will need to be your closest friend.

Termux is available on the Android App store, but updates may not be regular there. It is however available as a downloadable APK from F-Droid’s site or the F-Droid Store, which is an alternate app store for Android.

When you first run Termux, you will see a command prompt like most Linux terminals. Windows users might be familiar with the Command Prompt. Software meant to be run on this interface can be installed from this prompt using some commands.

The terminal prompt is practically like any other operating system. You can list files by typing ‘ls’. Typing ‘clear’ clears the screen. You can use the up and down arrow keys to scroll through the history of commands. You can look up the range of Linux commands and you should be able to get up to speed in no time. It’s a good idea to refer to documentation online on Linux commands, how to run Linux software and things will be clearer. Here are some easy tasks you can get done on Termux in moments.

Check your connection health

Termux can transform your phone into a network health checker in moments. The ping command can be used for example, to see the latency from your device to a server. This even could be your internet router, or to an internet router. Type ping 8.8.8.8 and you should see a stream of ping replies. The latency is mentioned at the end of each line. This pinging will continue till you stop it, by pressing Ctrl + C. You can also find command line interfaces for speedtest.net, even detailed traceroute software that can display all the hops your connection makes on the way to the destination.

Install software on Termux

Ping was an example of a tool that comes built into Termux, like any other Linux distribution. There are plenty of tools that can be installed. These are available over the repository, which is a library of hundreds and thousands of software you can install on your phone in this manner. This can be done using the apt install ______ command. For example, typing ‘apt install htop’ will install htop. Htop is a tool that helps you monitor the resources on your current setup. Type ‘htop’ on the Termux to run htop. Typing q quits it. Most Linux command line software use q to quit. Some others might use Esc.

Running IRC clients

Most of the world now uses WhatsApp and other messaging services but a lot of the enthusiast communities still use IRC and other messaging services called Matrix. IRC clients are available for the command line and they can be run on Termux. One of the easiest ways of getting on IRC is using a client called irssi. It can be installed using the command – apt install irssi and then run by typing irssi.

Using Termux as a web downloader

Termux also can be used as a downloader to download large files from web sites. There are torrent clients available for Termux, as well as http downloaders such as curl and wget. They should come bundled with Termux. If not, these can be installed using the command ‘apt install curl’ and ‘apt install wget’.

Connecting to a remote device using ssh

ssh is a tool that lets you connect to other devices. For example, if you have a Linux computer or laptop, you can use ssh from Termux to connect to it. Some routers even support incoming ssh connections and these interfaces can be used to control the router remotely. ssh is a widely used tool meant for monitoring and administration, so it’s impressive that this can now be done from your smartphone. Simply type ssh followed by the IP or name of the device on your network to access it.

Using Termux as a development environment

Termux can be used to write and run code, like any desktop PC or laptop. It can be used to brush up on programming languages like Python or scripting language like Shell / Bash script. Install a text editor such as Nano or Vim using the ‘apt install’ command and you should be on your way. Python too can be installed using the apt install command. With some addons and tweaking, Vim and Nano can be transformed into full-fledged development environments.

Accessing Termux-installed packages using Android

Termux requires users to run programs from the command line, but there are ways to create shortcuts to programs that run within Termux. One such way is to install the Termux:Widget from F-Droid’s site. Once you learn how to make simple Shell (.sh) scripts, you can place them in the .shortcuts directory. A widget can now be placed on your home screen by holding it down, then choosing the Termux:Widget widget. Tapping the script will now automatically open a Termux instance and run it.

The following commands first create a directory called .shortcuts, then change directory (cd) to the .shortcuts directory. The nano run_htop.sh creates a new file with that name.

mkdir .shortcuts
cd .shortcuts
nano run_htop.sh

Type in this code in the text editor, then save it by pressing Ctrl+X and save it.
#!/bin/sh
htop

The Termux:Widget widget should now show run_htop.sh. Tapping it will load Termux and htop on the phone.

Installing a desktop Linux distribution using Termux

If you want, you could consider a Bluetooth keyboard to use with your phone. There are even HDMI dongles that let you connect your phone to a TV or monitor. That in combination with Termux can let you run a Linux desktop operating system. We even wrote a feature recently on how to install a mainstream desktop Linux operating system on your phone, so be sure to check it out.

Termux is a simple way to get desktop-like capabilities straight on your phone. There is a lot of tinkering that can be done using it and we’ve only scratched the surface. There are a ton of other such interesting topics that we cover here at Reliance Digital so keep visiting us learn more about them.