Table of Contents

Introduction

Termux is an open source terminal emulator that runs the Linux environment on Android devices. It ported a large set of command line utilities to Android OS and can be used directly with no rooting or other special setup required. Its main goal is to bring the Linux command line experience to users of mobile devices.

Termux installs a minimal base system automatically, additional packages are available using a package manager.

Most commands available in Linux are accessible in Termux as well as the built-in Bash commands. There are also several other shells available, such as Zsh. Since all files are installed in the application directory, root is not required.

Termux has its own package ecosystem with over a thousand packages currently available for download. Alternatively, packages can be compiled from source as Termux supports a variety of build tools, including compilers for C, C++, Go, Rust, and more. Interpreters for common languages ​​like NodeJS, Python, Ruby are available too.

Use Cases

What can be done with Termux? For example, on an Android phone/tablet:

  • Accessing remote servers via ssh.
  • Learn the basics of Linux CLI.
  • Use proven tools from the Linux ecosystem.
  • Device automation with scripting and Termux Tasker add-on.
  • Use git for version control.
  • Use curl to access API endpoints.
  • Use rsync to sync and backup files.
  • Data processing with Python.
  • Programming in a development environment.
  • Not having enough fun? Connect a Bluetooth keyboard and hook up your device to an external display - a Linux workstation right in front of you.

Usage scenarios are not limited to the ones listed above, depending on your skills and imagination ~ πŸ’‘οΈ

I occasionally use Termux on my phone to update this site.

Addons

Termux can add some extra features by installing addons:

Termux:API
Expose device functionality as API to command line programs.
Termux:Boot
Run scripts when the device boots.
Termux:Float
Run Termux in a floating window.
Termux:Styling
Select the terminal’s color scheme and font.
Termux:Tasker
Provides a Tasker plug-in to execute Termux programs.
Termux:Widget
Start small scriptlets from the home screen.

Installation and Use

It is recommended to download Termux from F-Droid .

After installation, it can be used immediately. The terminal interface is as follows:

termux-ui

Basic gestures, like many regular Android apps.

  • Resize characters <- two-finger pinch to zoom or double-tap
  • Context menu <- long press anywhere on the terminal interface
  • Navigation Drawer <- Swipe inward from the left side of the screen

Switch Termux package repository

Execute the following command to switch package repositories to domestic (e.g. Tsinghua/BFSU) open source software mirror sites.

~ $  termux-change-repo

termux-change-repo

termux-change-repo-mirror

Access device storage with Termux

Grant Storage access permission to Termux. It will setup symlinks in directory ~/storage to standard directories like DCIM, Download, etc.

~ $  termux-setup-storage
# ~/storage/shared = /sdcard

Backing up

Before uninstalling or reinstalling Termux, remember to make a backup of the important files in the following directories:

  • /data/data/com.termux/files/usr
  • /data/data/com.termux/files/home

You can use the tar utility to place the backup file outside of the Termux private directory, such as /sdcard.

~ $  tar -cf /sdcard/termux.bak.tar /files/to/be/backed/up

Give an Example 🌰

Download a YouTube video on your phone.

~ $  pkg upgrade
~ $  pkg install python
~ $  curl -L https://yt-dl.org/downloads/latest/youtube-dl -o $PREFIX/bin/youtube-dl
# $PREFIX = /data/data/com.termux/files/usr
# is an exported environment variable in the Termux shell.
~ $  chmod a+rx $PREFIX/bin/youtube-dl
~ $  youtube-dl -o '~/storage/downloads/%(title)s.%(ext)s' https://youtu.be/PHe0bXAIuk0
# The above command will download the video corresponding to the given YouTube link to the `Download` directory of the phone's storage.

Tips

Termux uses the Volume down button to emulate the Ctrl key. For example, pressing Volume down + L on a touch keyboard sends the same input as pressing Ctrl + L on a hardware keyboard.

The result of using Ctrl in combination with a key depends on which program is used, but for many command line tools the following shortcuts works:

    Ctrl + A β†’ Move cursor to the beginning of line
    Ctrl + C β†’ Abort current process
    Ctrl + D β†’ Logout of a terminal session
    Ctrl + E β†’ Move cursor to the end of line
    Ctrl + K β†’ Delete from cursor to the end of line
    Ctrl + U β†’ Delete from cursor to the beginning of line
    Ctrl + W β†’ Clear a set of characters after a space
    Ctrl + Z β†’ Suspend current process
    Ctrl + L β†’ Clear the terminal

You can hide/show the Termux extra keys by holding down the device Volume Up key and then pressing the K key.

References: