Track 1 · Lesson 1 of 7
Getting started with Termux
Install Termux from F-Droid, open your first prompt, and learn the commands that show where you are and what sits around you.
Termux gives your Android phone a real Linux command line. In this lesson you install it and open the prompt. You also learn the handful of commands that answer two questions. Where am I, and what is here? Get these right and every later lesson gets easier.
What you'll be able to do
- Install Termux from F-Droid and open its prompt.
- Read a shell prompt and understand what it is telling you.
- Use
pwdandlsto see where you are and what a directory holds. - Move between directories with
cd. - Ask any command for help with
--helpandman.
Step 1: Install Termux
Termux is a terminal emulator and a small Linux environment, all in one app. It runs on Android without root, so nothing here can damage the rest of your phone.
Install it from F-Droid. That build is the current one and it still receives updates. The Play Store listing is old and abandoned. Treat it as a last resort.
If you install Termux from F-Droid, keep updating it from F-Droid. Installing over the top from another store can break your setup, and you may lose files.
Open the app once it finishes installing. You land straight in a prompt.
Step 2: Read the prompt
The prompt is the text the shell prints while it waits for you to type.
~ $
The ~ is shorthand for your home directory, the folder you start in. A $ means you are an ordinary user, not the system administrator. The cursor sits after the space, waiting for a command. You type on one line, then press Enter to run it.
Step 3: Find out where you are
Start with pwd. The name is short for print working directory. It shows the full path of the folder you are standing in.
$ pwd
/data/data/com.termux/files/home
That long path is your home directory. Termux keeps its own files inside the app's private storage, so all your work lives there. You will see this path often.
You never have to type that whole path. The tilde ~ always means the same directory, and cd ~ takes you home from anywhere.
Step 4: List what is there
The ls command lists what a directory holds. Run it on its own and it lists the directory you are in.
$ ls
A fresh install has an empty home directory, so ls prints nothing. That is not an error. It means there is nothing to show yet.
Hidden files start with a dot. By default ls hides them. Add -a to show everything, and -l for a long listing with details.
$ ls -la
total 0
drwx------ 2 u0_a123 u0_a123 4096 Jan 8 10:00 .
drwx------ 3 u0_a123 u0_a123 4096 Jan 8 10:00 ..
The two entries you see, . and .., exist in every directory. One dot means this directory. Two dots mean the parent directory. You will use both soon. The user name in the middle, u0_a123, is specific to your device. Yours will differ.
Step 5: Move between directories
The cd command changes directory. Give it a path and it takes you there. This path is absolute. It starts at the root of the filesystem.
$ cd /data/data/com.termux/files
$ pwd
/data/data/com.termux/files
Go back home with the tilde.
$ cd ~
$ pwd
/data/data/com.termux/files/home
That is a round trip. You moved away and came back. Lesson two goes into paths like these in full.
Step 6: Who you are, and how to ask for help
The whoami command prints the name of the user you run as.
$ whoami
u0_a123
On Android every app runs as its own user, so the name differs on every phone. You are not the system administrator. Some commands will refuse to run, and that is normal.
To ask a command what it can do, add --help.
$ ls --help
Usage: ls [OPTION]... [FILE]...
List information about the FILEs (the current directory by default).
Sort entries alphabetically if none of -cftuvSUX nor --sort is specified.
Mandatory arguments to long options are mandatory for short options too.
-a, --all do not ignore entries starting with .
-l use a long listing format
-h, --human-readable with -l, print sizes like 1K 234M 2G
...
The output is long, so it is cut short here. It goes on with more options, then ends with a note about exit status.
There is also man, the manual reader. Termux ships no man pages by default. Install them once, and then you can read the manual for any command.
$ pkg install man
Reading package lists... Done
Building dependency tree... Done
The following NEW packages will be installed:
man
0 upgraded, 1 newly installed, 0 to remove and 0 not upgraded.
Need to get 100 kB of archives.
...
Setting up man ...
Now you can open the manual.
$ man ls
LS(1) User Commands LS(1)
NAME
ls - list directory contents
SYNOPSIS
ls [OPTION]... [FILE]...
:
Press q to leave the manual and return to the prompt. When in doubt, --help is faster and always there.
Quick reference
| Command | What it does |
|---|---|
pwd | Print the full path of the current directory |
ls | List the contents of the current directory |
ls -la | Long listing, including hidden files |
cd PATH | Change to the directory at the given path |
cd ~ | Change to your home directory |
whoami | Print the name of the current user |
--help | Show a command's built-in help |
man COMMAND | Open the manual page for a command |
Next steps
Now that you can find your way around, learn how paths really work in Navigating the filesystem. When you want to look inside files, continue to Reading and searching text. For practice on a real puzzle, try Logs Never Lie.
Test yourself on this
4 questions and 1 task where you run a real command, with the reasoning explained either way.