Track 1 · Lesson 2 of 7
Navigating the filesystem
Learn absolute and relative paths, read listing options, make nested directories, and find files on Termux.
A filesystem is a tree of directories, and every file sits somewhere on it. Here you learn to name any spot on that tree and move to it. You also build your own branches and search them. The terminal stops being a mystery and becomes a place you know.
What you'll be able to do
- Tell an absolute path from a relative path.
- Use
.,..,~andcd -to move around quickly. - Read a long listing and understand every column.
- Create nested directories with
mkdir -p. - Find files by name and by type with
find, and view a tree withtree.
Step 1: Absolute and relative paths
An absolute path starts at the root, written as a forward slash, and spells out the whole route. A relative path starts from where you are.
$ cd /data/data/com.termux/files/home/projects
$ pwd
/data/data/com.termux/files/home/projects
Move next with a relative path. This one names a directory next to you, with no leading slash.
$ cd notes
$ pwd
/data/data/com.termux/files/home/projects/notes
Step 2: The dots and the tilde
A single dot . means the directory you are in. Two dots .. mean the one a level up.
$ cd ..
$ pwd
/data/data/com.termux/files/home/projects
The tilde ~ always means your home directory, wherever you are.
$ cd ~
$ pwd
/data/data/com.termux/files/home
There is also cd -. It returns you to the previous directory and prints where it took you.
$ cd ~/projects
$ cd -
/data/data/com.termux/files/home
cd - is a toggle. Run it again and you jump back to the directory you came from.
Step 3: Reading a long listing
A plain ls gives you names only. Add -l for a long listing with the details.
$ cd ~
$ mkdir -p projects/notes
$ printf 'buy milk\ncall plumber\n' > projects/notes/todo.txt
$ ls -l projects/notes
total 4
-rw------- 1 u0_a123 u0_a123 26 Jan 12 09:15 todo.txt
Read the line from left to right. -rw------- is the permission string, where the leading dash means a plain file. The 1 is the link count. Then come the owner and group, both u0_a123 here. Then the size in bytes, 26. Then the date, then the name.
Add -h to make sizes human readable, so large files show as kilobytes or megabytes.
$ ls -lh /data/data/com.termux/files/usr/bin
total 26M
-rwx------ 1 u0_a123 u0_a123 35K Jan 1 00:00 awk
-rwx------ 1 u0_a123 u0_a123 111K Jan 1 00:00 bash
...
That listing is abridged. The sizes now read as 35K and 111K rather than long byte counts. Add -a to include hidden files, or -R to list subdirectories as well.
$ ls -R projects
projects:
notes
projects/notes:
todo.txt
Add -R only on a small tree. On a large directory it prints thousands of lines. If a command runs away, press Ctrl and C to stop it.
Step 4: Making directories
mkdir makes a directory. With -p it creates every missing directory in the path. It stays quiet if the directory already exists.
$ mkdir -p work/logs/2026
$ ls -R work
work:
logs
work/logs:
2026
work/logs/2026:
Without -p, mkdir work/logs/2026 would fail. The path work/logs did not exist yet.
Step 5: Finding files
find searches a directory tree. Give it a starting directory, then a test. Here -name matches a file name.
$ find ~ -name "todo.txt"
/data/data/com.termux/files/home/projects/notes/todo.txt
Add -type f to match plain files only, or -type d for directories only.
$ find ~ -type f -name "*.txt"
/data/data/com.termux/files/home/projects/notes/todo.txt
Put the pattern in quotes, as in -name "*.txt". Without quotes the shell may expand the * before find sees it.
For a picture of a small tree, install tree.
$ pkg install tree
Reading package lists... Done
Building dependency tree... Done
The following NEW packages will be installed:
tree
0 upgraded, 1 newly installed, 0 to remove and 0 not upgraded.
Setting up tree ...
Then run it on your home directory.
$ tree ~
/data/data/com.termux/files/home
├── projects
│ └── notes
│ └── todo.txt
└── work
└── logs
└── 2026
5 directories, 1 file
Quick reference
| Command | What it does |
|---|---|
pwd | Print the full path of the current directory |
cd PATH | Change to the directory at the given path |
cd .. | Move up one level |
cd - | Return to the previous directory |
ls -l | Long listing with details |
ls -a | Include hidden files |
ls -h | Human readable sizes, with -l |
ls -R | List subdirectories as well |
mkdir -p PATH | Create a directory and any missing parents |
find DIR -name PATTERN | Find entries by name |
find DIR -type f | Find plain files only |
tree DIR | Show a directory tree |
Next steps
Now that you can reach any file, learn to read what sits inside it in Reading and searching text. To join commands and save their output, continue to Pipes and redirection. For practice with real files, 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.