21 Termux Basic Commands that You Should Know

Basic Termux Commands Techhyme

Termux is an Android app that provides a terminal emulator and a Linux environment to run on your Android device. It allows you to run many command-line tools and programs directly on your Android device, without the need to install any external software.

With Termux, you can install and run a wide variety of Linux packages and tools, such as text editors, compilers, and network utilities. You can also use Termux to access servers and perform remote tasks, or to run scripts and automate tasks on your Android device.

To use Termux, you will need to install the app from the Google Play Store or from the official Termux website. Once installed, you can start the app and use it like you would use a terminal emulator on a desktop operating system. You can enter commands and interact with the Linux environment just as you would on a desktop or server.

Here are some basic commands that you can use in Termux: 

  1. Update all the packages and dependencies installed on the system
  2. Grant storage permission
  3. Know Which directory you are in
  4. List all the files and directories
  5. Move forward in directories
  6. Move backward in directories
  7. Clear Screen
  8. Create a folder or a directory
  9. Delete a folder or a directory
  10. Delete Non-Empty directory or folder in termux
  11. Copy a file from one directory to another directory
  12. Search for the specific package in termux
  13. List all the available packages in termux
  14. Install a Package
  15. Uninstall a Package
  16. Install Python in termux
  17. Install Git in termux
  18. Download projects from GitHub repository
  19. Check all the running processes in termux
  20. See what’s inside a text file
  21. List all the installed Packages in termux

1. Update all the packages and dependencies installed on the system:

Command: apt update && apt upgrade

If any update is available it will ask you on the terminal if you want to upgrade or not, press Y if you want the update.

The apt update command is used to download package info from all configured sources, including package dependencies, updates, and security updates. The apt upgrade command is used to install newer versions of the packages currently installed on the system. Together, these commands can be used to update the system to the latest version of all packages.

It is generally a good idea to run apt update regularly to ensure that you have the latest security updates and package versions. However, be aware that apt upgrade may install new package versions that could potentially break compatibility with other packages or cause other issues on your system. It is always a good idea to carefully read the package upgrade notes before upgrading packages.

2. Grant storage permission:

Command: termux-setup-storage

termux-setup-storage is a script that is part of the Termux app for Android. It is used to set up access to the device’s storage from within the Termux environment.

This will allow you to access the device’s storage (e.g., SD card or internal storage) from within Termux, and also give Termux permission to modify the storage. This can be useful for installing packages and storing files in the Termux environment.

Keep in mind that termux-setup-storage requires the Termux app to have the WRITE_EXTERNAL_STORAGE permission, which you may need to grant when prompted.

3. Know Which directory you are in:

Command: pwd

The pwd command stands for “print working directory.” It is used to display the name of the current directory (also called the “working directory”).

The pwd command is useful for determining the current location in the file system, especially when you are navigating through multiple directories and want to know where you are currently located.

You can also use the pwd command to print the current working directory to a file or use it as input to other commands. For example:

Command: pwd > /path/to/file

4. List all the files and directories:

Command: ls

The ls command is used to list the files and directories in a directory. It is one of the most commonly used commands in Linux and is available on other operating systems as well.

Some common options for the ls command include:

  • -a: Include hidden files in the output.
  • -l: Display the output in a long format, including the permissions, owner, group, size, and modification time for each file.
  • -h: Display sizes in “human-readable” format (e.g., 1K, 234M).
  • -r: Reverse the order of the output.

Here are some examples of how to use the ls command:

  • ls: List the files and directories in the current directory.
  • ls -l: List the files and directories in the current directory in long format.
  • ls -a: List all files and directories in the current directory, including hidden files.
  • ls /path/to/directory: List the files and directories in the specified directory.

You can also combine multiple options, like this: ls -lh (long format with human-readable sizes).

5. Move forward in directories:

Command: cd storage

The cd command stands for “change directory” and is used to navigate between directories in a filesystem.

Here are some examples of how to use the cd command:

  • cd /home/user/documents: Change the current directory to the documents directory in the user home directory.
  • cd ..: Change the current directory to the parent directory (one level up in the filesystem).
  • cd: Change the current directory to the home directory of the current user.

Keep in mind that the cd command only works for directories that you have permission to access. If you try to navigate to a directory that you do not have permission to access, you will receive an error message.

6. Move backward in directories:

Command: cd ..

The cd .. command is used to navigate to the parent directory (one level up in the filesystem). It is often used in conjunction with the cd command to move up and down the directory tree.

You can also use multiple .. to move up multiple levels in the filesystem. For example, cd ../.. will move up two levels.

7. Clear Screen:

Command: clear

The clear command is used to clear the terminal screen. It is useful for cleaning up the terminal when it gets cluttered with output or when you want to start with a fresh screen.

The clear command does not take any arguments or options. It simply clears the screen and leaves the cursor at the top of the screen.

8. Create a folder or a directory:

Command: mkdir folderName

The mkdir command is used to create a new directory. It stands for “make directory.” You can also specify a path to create the directory in a specific location. For example:

Command: mkdir /path/to/new_directory

The mkdir command has a few options that you can use to modify its behavior. For example:

  • -p: Create any missing parent directories as needed.
  • -m: Set the permissions for the new directory.
  • -v: Print a message for each created directory.

Here is an example of using the -p option:

Command: mkdir -p new_directory/subdirectory

This will create the new_directory and subdirectory directories, even if the new_directory directory does not already exist.

9. Delete a folder or a directory:

Command: rmdir folderName

The rmdir command is used to delete an empty directory. It stands for “remove directory.” You can also specify a path to delete a directory in a specific location. For example:

Command:  rmdir /path/to/directory_name

The rmdir command has a few options that you can use to modify its behavior. For example:

  • -p: Remove any empty parent directories as well.
  • -v: Print a message for each removed directory.

Here is an example of using the -p option:

Command: rmdir -p directory_name/subdirectory

This will delete the subdirectory directory, as well as the directory_name directory if it is empty.

10. Delete Non-Empty directory or folder in termux:

Command: rm -rf folderName

The rm command is used to delete files and directories. The -r option tells the rm command to delete directories and their contents recursively, and the -f option tells it to force the delete operation, ignoring any prompts or errors.

Together, the rm -rf command is a very powerful command that can delete multiple files and directories and their contents, including hidden files, and it will not prompt you for confirmation.

Keep in mind that the rm -rf command is very dangerous and can delete important files and directories if used incorrectly. Be careful when using this command, and make sure you have a backup of any important files before deleting them.

Also, note that the rm -rf command will not work on directories that are protected, such as the root directory (/) or the current directory (.). Attempting to delete these directories will result in an error.

11. Copy a file from one directory to another directory:

Command: cp files-name file-path

The cp command is used to copy files and directories. It stands for “copy.” You can also use the cp command to copy a directory and its contents. For example:

Command: cp -r source_directory destination

This will copy the source_directory and all of its contents to the destination directory. The -r option tells the cp command to copy directories recursively.

The cp command has a few options that you can use to modify its behavior. For example:

  • -a: Preserve the file attributes and permissions of the source files.
  • -f: Force the copy operation, overwriting any existing files.
  • -i: Prompt the user before overwriting any existing files.
  • -n: Do not overwrite any existing files.
  • -u: Only copy files that are newer than the destination files.

Here is an example of using the -u option:

Command: cp -u file1.txt file2.txt

This will only copy the file1.txt file to file2.txt if file1.txt is newer than file2.txt. If file2.txt is newer or has the same modification time, it will not be overwritten.

Keep in mind that you need the appropriate permissions to copy files and directories. If you do not have permission to read the source file or write to the destination, you will receive an error message.

12. Search for the specific package in termux:

Command: pkg search package-name

The pkg search command is used to search for packages in the package manager database. It is used to find packages that are available to install on the system.

The above command will search the package database for packages that match the specified name and display a list of matching packages.

The pkg search command is often used with package managers such as apt on Debian-based systems and yum on Red Hat-based systems. It is not a standard command and may not be available on all systems.

Keep in mind that the pkg search command only searches the package database and does not search the filesystem for installed packages. It is used to find packages that are available to install, not packages that are already installed on the system. To search for installed packages, you can use the dpkg command on Debian-based systems or the rpm command on Red Hat-based systems.

13. List all the available packages in termux:

Command: pkg list-all

The pkg list-all command is used to list all packages that are available to install on the system. It is often used with package managers such as apt on Debian-based systems and yum on Red Hat-based systems.

To use the pkg list-all command, simply enter pkg list-all at the command prompt and press Enter. This will display a list of all available packages, along with their names and versions.

The pkg list-all command does not take any arguments or options. It simply lists all available packages in the package database.

14. Install a Package:

Command: pkg install packageName

The pkg install command is used to install a package on the system. It is often used with package managers such as apt on Debian-based systems and yum on Red Hat-based systems.

The pkg install command has a few options that you can use to modify its behavior. For example:

  • -y: Automatically assume yes and install without prompting.
  • -f: Force the installation, even if it might overwrite files.
  • -d: Download only; do not install.

Here is an example of using the -y option:

Command: pkg install -y packageName

This will install the package without prompting for confirmation.

Also, note that installing a package will typically also install any dependencies required by the package. These dependencies are packages that the package requires in order to function properly.

15. Uninstall a Package:

Command: pkg uninstall packageName

The pkg uninstall command is used to remove a package from the system. It is often used with package managers such as apt on Debian-based systems and yum on Red Hat-based systems.

The pkg uninstall command has a few options that you can use to modify its behavior. For example:

  • -y: Automatically assume yes and uninstall without prompting.
  • -f: Force the uninstallation, even if it might remove important files.

Here is an example of using the -y option:

Command: pkg uninstall -y packageName

This will uninstall the package without prompting for confirmation.

Also, note that uninstalling a package may also remove any packages that depend on it. Be careful when uninstalling packages, as it can cause other packages to stop functioning properly.

16. Install Python in termux:

Command: pkg install python

The pkg install python command is used to install the Python programming language on a system that is using a package manager such as apt on Debian-based systems or yum on Red Hat-based systems.

Keep in mind that you need the appropriate permissions to install packages. If you do not have permission to install packages, or if Python is not available in the package repository, you will receive an error message.

Once Python is installed, you can use it by entering the python command at the prompt and pressing Enter. This will start the Python interpreter, which allows you to enter Python commands and run them.

Command: python

You can also create and run Python scripts by creating a text file with a .py extension and running it with the python command.

Command: python script.py

17. Install Git in termux:

Command: pkg install git

The pkg install git command is used to install the Git version control system on a system that is using a package manager such as apt on Debian-based systems or yum on Red Hat-based systems.

To install Git, you can simply enter the pkg install git command at the prompt and press Enter. This will install the latest version of Git that is available in the package repository.

Once Git is installed, you can use it by entering git followed by the desired command at the prompt.

Git is a very powerful tool for managing source code and collaborating with others. For more information on how to use Git, you can consult the official documentation or seek out online resources and tutorials.

18. Download projects from GitHub repository :

Command: git clone Link-of-the-project

If you want to download any project from the github you can just use the above just change the Link-of-the-project with your link

e.g: git clone https://github.com/adi1090x/termux-style.git

19. Check all the running processes in termux:

Command: top

The top command is a system monitoring utility that displays information about the running processes on a system. It is commonly used to identify processes that are consuming a large amount of resources such as CPU, memory, or disk I/O.

When you run the top command, it will display a list of processes and their current status. The list is sorted by the amount of CPU usage, with the most CPU-intensive processes at the top.

The output includes the following information:

  • The current time and uptime of the system
  • The number of tasks and the CPU utilization
  • The amount of used and free memory and swap space
  • A list of the top processes, including their PID, user, CPU and memory usage, and command

The top command has several options and commands that you can use to customize the output and control the behavior of the command.

For example:

  • -d: Set the delay between updates
  • -p: Only show processes with the specified PID
  • k: Kill a process by PID

You can press h while top is running to display a list of available commands.

To exit the top command, press q.

Keep in mind that the top command requires root privileges to view and control all processes on the system. If you do not have sufficient privileges, you may not be able to view or control certain processes.

20. See what’s inside a text file:

Command: cat file-name

The cat command is a utility that is used to concatenate and display files. It stands for “concatenate.”

To use the cat command, you need to specify the name of the file you want to view. You can also use the cat command to view multiple files at the same time. For example:

Command: cat file1.txt file2.txt

This will display the contents of both file1.txt and file2.txt, one after the other.

The cat command has a few options that you can use to modify its behavior. For example:

  • -n: Display line numbers for each line of the file.
  • -s: Squeeze multiple blank lines into a single blank line.
  • -v: Show non-printing characters such as tabs and newlines.

Here is an example of using the -n option:

Command: cat -n file.txt

This will display the contents of the file.txt file with line numbers.

21. List all the installed Packages in termux:

Command: dpkg –list

The dpkg –list command lists all of the packages that are installed on your system. It displays the package name, version, and architecture for each package.

The –list option can be used with other options to filter the list of packages.

For example, you can use dpkg –list ‘*python*’ to list all packages that have “python” in their name. You can also use dpkg –list | grep ‘^ii’ to list only installed packages, or dpkg –list | grep ‘^rc’ to list only packages that are marked for removal.

You may also like:

Related Posts

Leave a Reply