Mastering Terminal Commands: Step-by-Step Guide for Linux & Termux

1. Start with Basic Daily Commands

pwd — Shows the current directory path you are in.

pwd

ls — Lists all files and folders in the current directory.

ls

cd foldername — Enters into a folder named foldername.

cd foldername

cd .. — Goes back one folder (to parent directory).

cd ..

mkdir newfolder — Creates a new folder named newfolder.

mkdir newfolder

rm file.txt — Deletes a file named file.txt.

rm file.txt

clear — Clears the terminal screen.

clear

cp file1.txt file2.txt — Copies file1.txt and names the copy file2.txt.

cp file1.txt file2.txt

mv oldname.txt newname.txt — Renames or moves a file.

mv oldname.txt newname.txt

2. Practice File Editing & Scripts

nano file.py — Opens a file called file.py for editing using the Nano editor.

nano file.py

nano script.sh — Opens or creates a shell script file.

nano script.sh

touch newfile.py — Creates a new empty file called newfile.py.

touch newfile.py

chmod +x script.sh — Makes a script executable (adds run permission).

chmod +x script.sh

python3 file.py — Runs a Python file using Python 3 interpreter.

python3 file.py

bash script.sh — Executes a shell script in the terminal.

bash script.sh

echo "print('Hello')" > hello.py — Writes a Python print statement into a file.

echo "print('Hello')" > hello.py

cat file.py — Displays the full content of file.py.

cat file.py

head -n 10 file.py — Shows the first 10 lines of the file.

head -n 10 file.py

tail -n 10 file.py — Shows the last 10 lines of the file.

tail -n 10 file.py

wc -l file.py — Counts the number of lines in the file.

wc -l file.py

file file.py — Tells you the file type of file.py.

file file.py

3. Learn Package Managers

pkg install git — Installs Git version control tool (Termux).

pkg install git

pkg install python — Installs Python in Termux (if not installed).

pkg install python

pkg install curl — Installs Curl, a command-line download tool.

pkg install curl

pkg install nodejs — Installs Node.js for JavaScript backend development.

pkg install nodejs

pip install flask — Installs Flask framework (Python backend).

pip install flask

pip install requests — Installs the requests module for APIs and HTTP calls.

pip install requests

pip install beautifulsoup4 — Installs BeautifulSoup for web scraping.

pip install beautifulsoup4

npm install express — Installs Express.js for building APIs (Node.js).

npm install express

npm install nodemon — Installs nodemon (auto restarts Node app on change).

npm install nodemon

apt update && apt upgrade — Updates and upgrades packages (like on Debian/Ubuntu).

apt update && apt upgrade

pip list — Shows all installed Python packages.

pip list

npm list — Shows all installed Node.js packages locally.

npm list

4. Use Git & Version Control

git --version — Checks if Git is installed and shows version.

git --version

git init — Initializes a new Git repository in your current folder.

git init

git clone <repo-link> — Copies a project from GitHub to your device.

git clone https://github.com/username/repo.git

git status — Shows changes in the current repo.

git status

git add . — Stages all changes to be committed.

git add .

git commit -m "message" — Saves your changes with a message.

git commit -m "Initial commit"

git remote add origin <url> — Links your project to GitHub.

git remote add origin https://github.com/username/repo.git

git push -u origin main — Uploads your code to GitHub (first time push).

git push -u origin main

git pull — Downloads new changes from GitHub to your local project.

git pull

git log — Shows history of commits in your project.

git log

5. Hosting & Deployment

python3 -m http.server — Launches a simple web server on localhost (default port 8000).

python3 -m http.server

flask run — Runs your Flask backend (usually on localhost:5000).

flask run

npm start — Starts your Node.js app as defined in package.json.

npm start

firebase deploy — Deploys your Firebase project (e.g., hosting, functions).

firebase deploy

vercel --prod — Deploys site to Vercel (if Vercel CLI is installed).

vercel --prod

netlify deploy — Uploads your static site to Netlify using CLI.

netlify deploy

chmod +x deploy.sh — Makes a deployment script file executable.

chmod +x deploy.sh

sh deploy.sh — Runs your deployment script.

sh deploy.sh

6. System Monitoring & Info

top — Shows live system usage: CPU, memory, tasks, and processes.

top

htop — A colorful and interactive version of top (if installed).

htop

df -h — Shows available and used disk space in human-readable format.

df -h

free -h — Displays memory (RAM) usage info.

free -h

uptime — Shows how long your system has been running and system load average.

uptime

whoami — Tells you the currently logged-in user.

whoami

uname -a — Shows system information like kernel version and architecture.

uname -a

termux-info — Shows system info specific to Termux (includes app version, storage).

termux-info

7. Network Tools

ping google.com — Tests if your device can reach a server and shows response time.

ping google.com

ip a — Lists all IP addresses and network interfaces.

ip a

ifconfig — Displays IP address and network data (might need installation).

ifconfig

nslookup example.com — Checks DNS record (IP info) for a domain name.

nslookup example.com

traceroute example.com — Traces the path packets take to reach a server.

traceroute example.com

netstat -tuln — Shows all open ports and services running (TCP/UDP).

netstat -tuln

curl ifconfig.me — Shows your public IP address (via curl).

curl ifconfig.me

wget https://site.com — Downloads a file or page from the internet.

wget https://site.com

8. File Permissions & Ownership

ls -l — Shows file details including permissions, owner, group, and size.

ls -l

chmod +x file.sh — Adds execute permission to a file.

chmod +x file.sh

chmod 755 script.sh — Sets full access for owner, read/execute for group/others.

chmod 755 script.sh

chmod 644 file.txt — Read/write for owner, read-only for others.

chmod 644 file.txt

chown username file.txt — Changes the ownership of the file to a specific user.

chown username file.txt

chgrp groupname file.txt — Changes the group owner of a file.

chgrp groupname file.txt

umask — Shows the default permission mask for new files and folders.

umask

9. Archive & Compression Tools

zip archive.zip file1.txt file2.txt — Compresses files into a .zip archive.

zip archive.zip file1.txt file2.txt

unzip archive.zip — Extracts a .zip archive.

unzip archive.zip

tar -cvf archive.tar file1 file2 — Creates a .tar file (not compressed).

tar -cvf archive.tar file1 file2

tar -xvf archive.tar — Extracts a .tar archive.

tar -xvf archive.tar

tar -czvf archive.tar.gz foldername — Creates a compressed .tar.gz archive.

tar -czvf archive.tar.gz foldername

tar -xzvf archive.tar.gz — Extracts a compressed .tar.gz archive.

tar -xzvf archive.tar.gz

gzip file.txt — Compresses a file using gzip (adds .gz extension).

gzip file.txt

gunzip file.txt.gz — Decompresses a gzip file.

gunzip file.txt.gz

10. Mastery Recap & Final Motivation

You’ve just walked through the **command-line mastery plan** — from basic commands to deployment, version control, system monitoring, networking, file permissions, and even compression tools.

  • 📁 Basic Navigation — move with confidence
  • 📝 File Editing — create, run, and manage scripts
  • 📦 Package Managers — control your tools
  • 🔧 Version Control — Git like a pro
  • 🌐 Hosting & Deploying — launch your apps
  • 🖥️ Monitoring — know your system inside out
  • 🌍 Networking — diagnose and test connectivity
  • 🔐 Permissions — protect and control access
  • 🗜️ Compression — pack and unpack data efficiently

Every great developer starts from the **terminal**. Learn one command per day. Repeat. Break things. Fix them. Learn again. Build your own path.

“Master the shell, and you master your world.”

Case Study 1 – Working With Images in Terminal (Using magick)

🖼️ Objective: Convert, resize, and compress images using CLI.

1.1 Install ImageMagick (if not yet installed)

This tool gives you magick command for image processing.

pkg install imagemagick

1.2 Check Available Image Formats

This ensures you can convert between formats like JPEG, PNG, WebP, etc.

magick -list format

1.3 Convert JPG to PNG

Syntax: magick input.jpg output.png

magick input.jpg output.png

1.4 Resize Image (by Width)

This command resizes the width to 500px while keeping aspect ratio.

magick input.jpg -resize 500 output.jpg

1.5 Resize Image (by Width x Height)

This resizes to fixed width and height. May distort aspect ratio.

magick input.jpg -resize 800x600 output.jpg

1.6 Compress Image (Reduce File Size)

Adjust quality (e.g., 60) to reduce size without much loss in visible quality.

magick input.jpg -quality 60 output.jpg

1.7 Remove Image Metadata (for Privacy)

Strips hidden data like device info, GPS, etc., from the image file.

magick input.jpg -strip output.jpg

1.8 Convert Image to WebP Format

Useful for websites. WebP is lightweight and web-optimized.

magick input.jpg output.webp

1.9 Batch Convert All JPGs to PNGs

This command loops through all JPGs and saves as PNGs.

for i in *.jpg; do magick "$i" "${i%.jpg}.png"; done

Case Study 2 – Working With Audio (Using ffmpeg)

🎧 Objective: Convert, trim, compress, and extract audio using CLI.

2.1 Install FFmpeg

Use this in Termux to get the ffmpeg package.

pkg install ffmpeg

2.2 Convert MP3 to WAV

Change audio format using a simple command.

ffmpeg -i input.mp3 output.wav

2.3 Trim Audio (start at 00:00, play 30s)

This trims first 30 seconds only.

ffmpeg -i input.mp3 -ss 00:00:00 -t 30 output.mp3

2.4 Compress Audio (Lower Bitrate)

This reduces file size by lowering bitrate.

ffmpeg -i input.mp3 -b:a 96k output.mp3

2.5 Extract Audio from a Video File

Use this to get the audio (MP3) from a video.

ffmpeg -i video.mp4 -q:a 0 -map a output.mp3

2.6 Merge Two Audio Files

This joins two MP3 files into one audio track.

ffmpeg -i "concat:file1.mp3|file2.mp3" -acodec copy output.mp3

Case Study 3 – Working With Video (Using ffmpeg)

🎬 Objective: Convert, trim, resize, compress, and manipulate videos using CLI.

3.1 Convert MP4 to AVI

Change format from MP4 to AVI.

ffmpeg -i input.mp4 output.avi

3.2 Trim Video (First 10 seconds)

Extracts only first 10 seconds from a video.

ffmpeg -i input.mp4 -ss 00:00:00 -t 10 output.mp4

3.3 Resize Video to 720p

Scales down video resolution to 1280x720.

ffmpeg -i input.mp4 -vf scale=1280:720 output.mp4

3.4 Compress Video (Reduce Quality)

Adjust bitrate to compress video and save space.

ffmpeg -i input.mp4 -b:v 800k output.mp4

3.5 Extract a Frame as Image

Takes a screenshot at 1-second mark (or change time).

ffmpeg -i input.mp4 -ss 00:00:01 -vframes 1 frame.png

3.6 Mute a Video (Remove Audio)

Removes audio completely from a video.

ffmpeg -i input.mp4 -an output.mp4

Case Study 4 – Voice Cloning & Text-to-Speech (With Gender Options)

🎤 Objective: Convert text to natural-sounding voice, and optionally clone a voice.

4.1 Install Python & Required Libraries

Start by installing Python and pip support:

pkg install python && pip install --upgrade pip

4.2 Text-to-Speech Using gTTS (Google)

Install gTTS (Google Text-to-Speech):

pip install gTTS

Run this Python code to create MP3:

python3 -c "from gtts import gTTS; tts = gTTS('Hello from Termux', lang='en'); tts.save('voice.mp3')"

Play the file (ensure mpv or termux-media-player is installed):

termux-media-player play voice.mp3

4.3 Text-to-Speech with Voice Gender (Using pyttsx3)

Install pyttsx3 and dependencies:

pip install pyttsx3

Then run the following script:

python3 -c " import pyttsx3 engine = pyttsx3.init() voices = engine.getProperty('voices') engine.setProperty('voice', voices[1].id) # Use voices[0] for male engine.say('Hello, I am a female voice.') engine.runAndWait() "

4.4 Voice Cloning (Using ElevenLabs API)

Create an account at ElevenLabs.io, get your API key, then:

Install requests:

pip install requests

Sample API call (replace YOUR_API_KEY):

curl -X POST "https://api.elevenlabs.io/v1/text-to-speech/VOICE_ID" \ -H "xi-api-key: YOUR_API_KEY" \ -H "Content-Type: application/json" \ -d '{"text":"Hello there. I am your cloned voice","voice_settings":{"stability":0.5,"similarity_boost":0.5}}' --output output.mp3

You can upload your voice sample and clone from it.

4.5 Convert Cloned Voice or TTS to Other Formats

Use ffmpeg to convert to another format:

ffmpeg -i output.mp3 output.wav

Case Study 5 – Move Your Files to Storage (Phone or PC)

📂 Goal: Export all output files (TTS, images, video, etc.) to your device's storage.

5.1 Move Converted Images to Internal Phone Storage

Move output.jpg to Downloads folder:

mv output.jpg /sdcard/Download/

You can also move to DCIM folder:

mv output.jpg /sdcard/DCIM/

5.2 Move Audio Files (TTS or Cloned Voice)

Move generated voice.mp3 or output.wav to Music folder:

mv voice.mp3 /sdcard/Music/
mv output.wav /sdcard/Music/

5.3 Move Video Output to Gallery or DCIM

Send final output.mp4 to phone’s gallery:

mv output.mp4 /sdcard/DCIM/

Or move to Movies:

mv output.mp4 /sdcard/Movies/

5.4 General Tip – View Phone Storage Structure

To see available folders in Termux:

ls /sdcard/

Use this to navigate and verify your paths.

5.5 Move from Termux to Computer via USB (Optional)

1. Connect phone to PC via USB cable.

2. Enable “File Transfer Mode” on phone.

3. Move files to /sdcard/Download first:

mv myfile.ext /sdcard/Download/

4. Then open your phone on PC and drag the file from “Download”.

5.6 Optional: Use ADB Pull to Copy from Phone to PC

Use if ADB is set up on your PC:

adb pull /sdcard/Download/output.mp4

Case Study 6 – File Encryption & Decryption (Secure CLI)

🔐 Objective: Encrypt sensitive files and decrypt them securely.

6.1 Install OpenSSL

pkg install openssl-tool

6.2 Encrypt a File with Password

openssl enc -aes-256-cbc -salt -in secret.txt -out secret.txt.enc

6.3 Decrypt the Encrypted File

openssl enc -aes-256-cbc -d -in secret.txt.enc -out secret_decrypted.txt

Case Study 7 – Download Files from the Web

🌐 Objective: Use CLI to download files using curl or wget.

7.1 Install curl & wget

pkg install curl wget

7.2 Download File Using curl

curl -O https://example.com/file.zip

7.3 Download File Using wget

wget https://example.com/file.zip

Case Study 8 – Fun with Game Apps in Termux/Linux

🎮 Objective: Play simple terminal games and ASCII-based fun apps.

8.1 Install Terminal Games (cowsay, bastet, nsnake)

pkg install cowsay bastet nsnake

8.2 Play Snake Game

nsnake

8.3 ASCII Talk with cowsay

cowsay "You are mastering Termux!"