Catalog / Termux Environment Cheatsheet

Termux Environment Cheatsheet

A comprehensive cheat sheet for navigating and utilizing the Termux terminal environment on Android. This guide covers essential commands, package management, file manipulation, and customization options to enhance your mobile development and system administration tasks.

Basic Commands & Navigation

Essential Commands

pwd

Print working directory - shows the current directory.

ls

List directory contents - displays files and directories in the current location.

cd <directory>

Change directory - navigates to the specified directory.

mkdir <directory>

Make directory - creates a new directory with the given name.

rm <file>

Remove file - deletes the specified file.

rmdir <directory>

Remove directory - deletes the specified directory (must be empty).

mv <source> <destination>

Move or rename - moves or renames a file or directory.

cp <source> <destination>

Copy - copies a file or directory to the specified destination.

File Manipulation

cat <file>

Concatenate and print - displays the contents of a file.

nano <file>

Text editor - opens the nano text editor to create or modify a file.

head <file>

Display first lines - shows the first few lines of a file.

tail <file>

Display last lines - shows the last few lines of a file.

grep <pattern> <file>

Search - searches for a specific pattern within a file.

chmod <permissions> <file>

Change permissions - modifies the read, write, and execute permissions of a file.

Package Management (pkg)

pkg update

Update package lists - synchronizes the package index files from their sources.

pkg upgrade

Upgrade installed packages - installs the newest versions of all packages currently installed on the system.

pkg install <package>

Install a package - installs the specified package and its dependencies.

pkg uninstall <package>

Uninstall a package - removes the specified package from the system.

pkg search <package>

Search for a package - searches for packages based on a keyword.

pkg show <package>

Show package information - displays detailed information about a specific package.

Advanced Termux Usage

SSH and Remote Access

pkg install openssh

Install OpenSSH - installs the OpenSSH server, allowing remote access to Termux.

sshd

Start SSH server - starts the SSH daemon.

ssh <user>@<ip_address> -p <port>

Connect to SSH server - connects to a remote SSH server using the specified username, IP address, and port.

whoami

Show current user - displays the current username.

ifconfig

Configure network interfaces - shows network interface configuration (requires net-tools).

passwd

Change password - changes the password for the current user.

Background Processes and Task Management

& (append to command)

Run in background - runs a command in the background.

jobs

List background jobs - displays a list of background processes.

fg <job_id>

Bring job to foreground - brings a background process to the foreground.

bg <job_id>

Send job to background - sends a stopped job to the background.

kill <pid>

Kill process - terminates a process with the specified process ID (PID).

top

Display processes - shows a dynamic real-time view of running processes.

Termux Utilities

termux-setup-storage

Setup storage - grants Termux access to external storage.

termux-change-repo

Change repository - allows changing the Termux package repository.

termux-battery-status

Show battery status - displays battery information.

termux-wifi-connectioninfo

Show wifi info - displays information about the current WiFi connection.

termux-notification

Send notification - sends a notification to the Android system.

termux-clipboard-get

Get clipboard content - retrieves the content from the clipboard.

termux-clipboard-set

Set clipboard content - sets the content to the clipboard.

Configuration and Customization

Termux Configuration Files

~/.termux/termux.properties

Termux properties - configuration file for Termux settings.

~/.bashrc

Bash configuration - bash startup file, used to customize the shell environment.

~/.zshrc

Zsh configuration - zsh startup file, used to customize the shell environment.

$PREFIX

Termux prefix - the installation directory for packages (/data/data/com.termux/files/usr).

termux-change-repo

Change repository - change Termux package repository.

pkg install termux-tools

Install Termux tools - installs a collection of Termux-specific tools.

Customizing the Shell

`export PS1=”…``

Customize prompt - modifies the shell prompt. Example: export PS1="\u@\h:\w\$ "

alias <alias_name>='command'

Create alias - creates a shortcut for a command. Example: alias la='ls -la'

pkg install zsh

Install Zsh - installs the Zsh shell for advanced customization.

chsh -s /data/data/com.termux/files/usr/bin/zsh

Change shell - changes the default shell to Zsh.

oh-my-zsh

Install oh-my-zsh - framework for managing zsh configuration.

pkg install fish

Install fish - installs the fish-shell.

Termux Styling

pkg install termux-style

Install termux-style - install program for changing the terminal colors and font.

termux-style

Launch termux-style - interactive program to customize the terminal appearance.

~/.termux/colors.properties

Colors config file - advanced way to customize the terminal colors.

~/.termux/font.ttf

Custom fonts - path for custom font file in ttf format.

Troubleshooting and Tips

Common Issues

Problem: pkg commands are slow or failing.
Solution: Ensure your internet connection is stable. Try changing the repository using termux-change-repo.

Problem: Unable to access external storage.
Solution: Run termux-setup-storage and grant the necessary permissions.

Problem: SSH connection refused.
Solution: Ensure the SSH server is running (sshd) and that the correct port is used. Check firewall settings if applicable.

Problem: Command not found.
Solution: Make sure the package containing the command is installed. Use pkg search <command> to find the package and install it with pkg install <package>.

Useful Tips and Tricks

Use tab completion to speed up command typing. Press Tab to auto-complete commands, file paths, and package names.

Customize your Termux environment by modifying ~/.bashrc or ~/.zshrc to add aliases, functions, and custom prompts.

Install a text-based web browser like w3m or lynx to browse the web from the terminal.

Utilize tmux or screen for persistent terminal sessions that can be detached and reattached later.

Leverage Termux’s API to interact with Android features using commands like termux-notification, termux-clipboard-get, and termux-vibrate.