Termux Commands

# Arguments enclosed in [ ] are optional and can be omitted.

Directory Management

pwd

pwd = print working directory

Show current directory

pwd

ls

ls = list

Show all files and directories

ls [DIR]
ls -l [DIR]
ls -a [DIR]
ls -lh [DIR]
ls -lt [DIR]
ls -ltr [DIR]
ls -lah [DIR]
ls -d */
-l
Show long format
-a
Show all entries (including hidden files)
-h
Human-readable size(KB・MB・GB)
-t
Sort by modification time
-r
Reverse
-lah
Format + All entries + Human-readable
-d */
List directories only

cd

cd = change directory

cd [DIR]

mkdir

mkdir = make directory

Creates a new directory (folder)

mkdir [DIR]/myfolder
mkdir dir1 dir2 dir3
mkdir [DIR]/{dir1,dir2,dir3}
mkdir -p [DIR]/myfolder
mkdir -v myfolder
"my fodler"
If the file name contains spaces, use double quotes
dir1 dir2 dir3
Create multiple directories
-p
Creates directory with missing parents
-v
Show what the command is doing

rmdir

rmdir = remove directory

Removes an empty directory (folder)

rmdir [DIR]/Empty DIR
rmdir -p dir1/dir2/dir3
-p
Deletes dir3 → dir2 → dir1 if empty

tree

pkg install tree

Display the directory structure as a tree

tree [DIR]
tree -L Num [DIR]
tree -a [DIR]
tree -d [DIR]
tree -f [DIR]
tree -h [DIR]
-L Num
-L 2 = display up to 2 levels of directories
-a
Show all entries (including hidden files)
-d
List directories only
-f
Show full path
-h
Human-readable size(KB・MB・GB)

File Management

cp

Copy file

cp [DIR]/file [DIR]/
cp file1 file2
cp -i [DIR]/file [DIR]/
cp -n [DIR]/file [DIR]/
cp -r [DIR]/folder [DIR]/
cp -r code/. .
file1 file2
Copy file1.txt to file2.txt (overwrites if exists)
-i
Ask before overwriting
-n
Do not overwrite existing files
-r
Copy a folder including all its contents
cp -r code/. .
Copy all contents of the code folder into the current directory

mv

Move or rename file

mv [DIR]/file [DIR]/
mv file1 file2
mv dir1/ dir2/
mv -i [DIR]/file [DIR]/
mv -n [DIR]/file [DIR]/
file1 file2
  • Renames file1 to file2
  • Overwrites file2 if it already exists
dir1/ dir2/
  • Renames dir1 to dir2
  • Overwrites dir2 if it already exists
-i
Ask for confirmation if the target file exists
-n
Do not overwrite an existing file

rm

Delete file

rm [DIR]/file
rm file1 file2
rm *.txt
rm -i [DIR]/file
rm -r [DIR]
rm -f [DIR]/file
file1 file2
Delete multiple files
*.txt
All files ending with .txt
-i
Ask before deleting
-r
Delete folders and their contents
-f
No prompts, no errors for missing files

touch

Create empty file

If the file exists, update the timestamp

touch [DIR]/myfile
touch file1 file2 file3
touch [DIR]/{file1,file2,file3}
"my file"
If the file name contains spaces, use double quotes
file1 file2 file3
Create multiple files

echo

Write to a file

Creates a new file if it does not exist

echo "text" > [DIR]/filename
echo "text" >> [DIR]/filename
echo -n "text" > [DIR]/filename
echo -e "text" > [DIR]/filename
>
overwrite a file
>>
append to a file
-n
Do not add newline at the end
-e
Enable interpretation of backslash escapes (\n, \t, etc.)

cat

Display and concatenate file contents

cat [DIR]/filename
cat file1 file2
cat file1 file2 > newfile
cat >> [DIR]/filename
cat -n [DIR]/filename
cat -b [DIR]/filename
cat -A [DIR]/filename
cat -E [DIR]/filename
cat -T [DIR]/filename
cat -s [DIR]/filename
file1 file2
Display multiple files
file1 file2 > newfile
Merge files and create a new file
>>
  • Append to a file
  • Type text → Enter → Ctrl+D to finish
-n
Show file with line numbers
-b
Show file with line numbers on non-empty lines
-A
Show all characters, including line ends and tabs
-E
Show $ at the end of each line
-T
Show tabs as ^I
-s
Squeeze multiple blank lines into one

less

View file page by page

less [DIR]/filename
less -N [DIR]/filename
less -S [DIR]/filename
less -i [DIR]/filename
less +Num [DIR]/filename
LESS='-R' less [DIR]/filename
Space
Move to the next page
b
Move to the previous page
↑ / ↓
Scroll one line at a time
g
Go to the beginning of the file
G
Go to the end of the file
/Text
Search for a text string
n
Go to the next search result
q
Quit less
-N
Show line numbers
-S
No line wrap / horizontal scroll
-i
Case-insensitive search(/Text)
+Num
Start at end of file
(+100 = start at line 100)
LESS='-R'
Display raw color codes

tail

Show last 10 lines

tail [DIR]/filename
tail file1 file2
tail -n Num [DIR]/filename
tail -f [DIR]/filename
file1 file2
Show Last 10 lines of each file
-n 5
Last 5 lines
-f
Follow new lines in real time

rsync

pkg install rsync
rsync -av --exclude='node_modules' --exclude='dist' ./ ~/storage/shared/Code
-a
Keeps permissions, timestamps, etc
-v
Shows what’s happening
--exclude
Folders to ignore
./
Current directory contents
~/storage/shared/Code
Destination folder
  • Copy all contents excluding node_modules and dist

Path & Pattern Shortcuts

Wildcard

Special character used to match multiple files or directories without typing their exact names

*
Matches zero or more characters
*.txt
a.txt, b.txt, hello.txt (all .txt files)
?
Matches exactly one character
file?.txt
file1.txt, fileA.txt
[]
Matches any character in the set
file[12].txt
file1.txt or file2.txt
[! ]
Matches any character not in the set
file[!1].txt
file2.txt, file3.txt (anything except 1)

Brace Expansion

Shell feature that generates multiple strings from a pattern using {}

echo file{1,2,3}.txt
file1.txt file2.txt file3.txt
touch file{1..5}.txt
Creates file1.txt to file5.txt at once

Path Shortcut

Way to refer to a long file or directory path with a shorter alias

.
Current directory (stays in the same place)
..
Parent directory (go up one level)
~
Home directory (/data/data/com.termux/files/home)
-
Previous directory (where you were last, used with cd -)

Text Editing

nano

pkg install nano
nano [DIR]/filename
  • Create a file if it does not exist

vim

Vim is more powerful than nano

pkg install vim
vim [DIR]/filename
  • Create a file if it does not exist
  • Vim has different modes, and the keys do different things depending on the mode
Normal
  • Move
  • Delete
  • Copy
  • Search
Insert
Type text
Command-line
  • Save
  • Quit
  • Search / Replace

Insert Text (Insert Mode)

i
Insert at cursor
I
Insert at beginning of line
a
Insert after cursor
A
Insert at end of line
o
Open a new line below
O
Open a new line below
  • Type normally while in insert mode
  • Press Esc to go back to normal mode

Move Around (Normal Mode)

h
← left
j
↓ down
k
↑ up
l
→ right
0
Beginning of line
$
End of line
gg
Top of file
G
Bottom of file

You can also use arrow keys in Termux if it’s easie

Delete / Copy / Paste

x
Delete character
dd
Delete line
yy
Copy line
p
Paste below cursor
P
Paste above cursor

Undo / Redo

u
undo
Ctrl + r
redo

Save And Quit (Command-line Mode)

:w
Save
:q
Quit
:wq
Save and quit
:q!
Quit without saving

Search And Replace

/text → press Enter → n for next, N for previous
Search
:s/old/new/
Replace in line
:%s/old/new/g
Replace in whole file

Package Management

Install

Install packages

pkg install <package>
pkg install pkg1 pkg2 pkg3
pkg1 pkg2 pkg3
Install multiple packages

Update

Update and upgrade packages

pkg update
pkg upgrade
pkg update && pkg upgrade
update
Refresh package list
upgrade
Upgrade installed packages to newest versions
pkg update && pkg upgrade
Refresh list & upgrade packages

Uninstall

Uninstall packages

pkg uninstall <package>
pkg uninstall pkg1 pkg2 pkg3
pkg1 pkg2 pkg3
Uninstall multiple packages

List Installed

Lists all installed packages

pkg list-installed

Available Package List

List all available packages

pkg list-all

Check Package Details

Display info about an installed package (version, description, dependencies)

pkg show <package>

Restrictions / Permissions

chmod

Makes a script file executable

Required for .sh scripts and Termux Widget scripts

chmod +x filename
chmod -R +x [DIR]
+x
Adds execute permission
-R
All files and subdirectories

termux-setup-storage

Enable Android storage access

termux-setup-storage

Required to access:

  • Downloads
  • DCIM
  • shared storage
  • /sdcard paths

termux-wake-lock

It keeps the CPU awake so your processes don’t get paused or killed when the screen turns off

termux-wake-lock
termux-wake-unlock
termux-wake-lock
Enable wake lock
termux-wake-unlock
Disable wake lock

Exit / Session

exit

Exit current session

exit
logout

Ctrl + C

Stop a running command (interrupt)

Ctrl + C

Ctrl + Z

Suspend current process (pause)

Ctrl + Z

command &

Run command in background

npm run dev &
npm run dev &
Runs without blocking the terminal

jobs

Show background jobs

Lists suspended/background tasks

jobs

fg

Foreground (bring back to active)

fg

bg

Background (resume in background)

bg

exec

Reloads the shell

exec bash

tmux

Install tmux

pkg install tmux

Start tmux

tmux
tmux new -s mysession
tmux new -s mysession
Start a named session

Detach (Run In Background)

Ctrl + b → d
  • This keeps everything running in the background

Reattach (Come Back)

tmux attach
tmux attach -t mysession
tmux a
tmux attach -t mysession
If you used a name

Create A New Window

Ctrl + b → c

Switch Windows

Ctrl + b → n
Ctrl + b → p
Ctrl + b → n
Next window
Ctrl + b → p
Previous window

Split The Screen

Ctrl + b → "
Ctrl + b → %
Ctrl + b → "
Horizontal split
Ctrl + b → %
Vertical split

Exit tmux

exit
tmux kill-server
exit
Inside tmux
tmux kill-server
Kill all sessions

List Sessions

tmux ls

Combine Multiple Commands

&&

command1 && command2
pkg update && pkg upgrade
  • Run command2 only if command1 succeeds

;

command1 ; command2
echo "Hello" ; echo "World"
  • Run both commands no matter what (success or failure)

||

command1 || command2
mkdir test || echo "Directory already exists"
  • Run command2 only if command1 fails