Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save ranjit485/0b8850d706b948196f7f4eb0e1fe7eaf to your computer and use it in GitHub Desktop.

Select an option

Save ranjit485/0b8850d706b948196f7f4eb0e1fe7eaf to your computer and use it in GitHub Desktop.
Linux and Termux Cheat Sheet by Ranjit485

Here’s a Linux Command Cheat Sheet with the most commonly used commands:


File and Directory Management

Command Description
ls List files and directories.
ls -l Long listing format (detailed view).
ls -a List all files, including hidden files.
pwd Print working directory (current location).
cd /path/to/directory Change directory.
mkdir directory_name Create a new directory.
rm file_name Remove a file.
rm -r directory_name Remove a directory and its contents.
cp source destination Copy a file or directory.
mv source destination Move or rename a file or directory.
touch file_name Create a new empty file.
find /path -name file_name Search for a file or directory.
tree Display directories and files in a tree-like structure.

File Viewing and Editing

Command Description
cat file_name Display the contents of a file.
tac file_name Display the contents of a file in reverse order.
less file_name View file content one screen at a time.
head file_name Show the first 10 lines of a file.
tail file_name Show the last 10 lines of a file.
nano file_name Open file in the Nano text editor.
vim file_name Open file in the Vim text editor.
wc file_name Count lines, words, and characters in a file.
diff file1 file2 Compare two files line by line.
grep "text" file_name Search for text within a file.

File Permissions and Ownership

Command Description
chmod 755 file_name Change file permissions (rwxr-xr-x).
chown user file_name Change file ownership to a specific user.
chgrp group file_name Change group ownership of a file.
ls -l View file permissions and ownership.

Process Management

Command Description
ps List running processes.
top Display real-time system resource usage.
htop Interactive process viewer (requires installation).
kill PID Kill a process by its Process ID (PID).
killall process_name Kill all processes with a specific name.
bg Resume a job in the background.
fg Bring a job to the foreground.
jobs List background jobs.

Disk Usage

Command Description
df -h Display disk space usage (human-readable).
du -h Show directory/file size (human-readable).
du -sh directory_name Show the total size of a directory.
mount /dev/device /mnt/point Mount a device to a directory.
umount /mnt/point Unmount a mounted device.

Networking

Command Description
ping domain.com Check network connectivity to a domain or IP.
curl -I URL Fetch HTTP headers of a URL.
wget URL Download a file from the internet.
ifconfig Display network interfaces (deprecated, use ip).
ip a Show IP addresses and network interfaces.
netstat -tuln List open ports and services.
ssh user@host Connect to a remote server via SSH.

User Management

Command Description
whoami Show the current logged-in user.
who Show all logged-in users.
adduser username Add a new user.
passwd username Change the password for a user.
usermod -aG group username Add a user to a group.
id username Show a user's ID, groups, and other details.

Package Management (Ubuntu/Debian)

Command Description
sudo apt update Update package lists.
sudo apt upgrade Upgrade installed packages.
sudo apt install package_name Install a package.
sudo apt remove package_name Remove a package.
dpkg -l List installed packages.

System Information

Command Description
uname -a Show kernel version and system info.
hostname Display the system's hostname.
uptime Show system uptime.
free -h Display memory usage.
cat /proc/cpuinfo Show CPU details.
cat /proc/meminfo Show memory details.

Archiving and Compression

Command Description
tar -cvf archive.tar files/ Create a tar archive.
tar -xvf archive.tar Extract a tar archive.
tar -czvf archive.tar.gz files/ Create a compressed tar.gz archive.
gzip file_name Compress a file using gzip.
gunzip file_name.gz Decompress a gzip file.
zip archive.zip files/ Create a zip archive.
unzip archive.zip Extract a zip archive.

Permissions Shortcuts

Permission Symbol Command Example
Read (r) 4 chmod 400 file_name
Write (w) 2 chmod 200 file_name
Execute (x) 1 chmod 100 file_name
Read/Write/Exec 7 chmod 700 file_name

Here’s a Termux Cheat Sheet for sending Discord webhooks and making API calls using curl:


General Setup

  1. Update and Upgrade Packages:

    pkg update && pkg upgrade
  2. Install Necessary Tools:

    pkg install curl jq

Sending Discord Webhooks

1. Basic Webhook Message

curl -H "Content-Type: application/json" \
-d '{"content":"Your Message Here"}' \
<WEBHOOK_URL>

2. Send a Message with an Embed

curl -H "Content-Type: application/json" \
-d '{
  "content": "Optional plain text message",
  "embeds": [{
    "title": "Embed Title",
    "description": "Embed Description",
    "color": 16711680
  }]
}' \
<WEBHOOK_URL>
  • Replace <WEBHOOK_URL> with your Discord webhook URL.
  • color is a decimal representation of a hex color (e.g., 0xFF0000 = 16711680 for red).

3. Send a File

curl -F "file=@/path/to/your/file.txt" \
<WEBHOOK_URL>

API Calls Using curl

1. GET Request

curl -X GET <API_URL>

2. POST Request

curl -X POST -H "Content-Type: application/json" \
-d '{"key":"value"}' \
<API_URL>

3. Headers Example

curl -H "Authorization: Bearer <TOKEN>" \
-H "Content-Type: application/json" \
-X GET <API_URL>

4. Query Parameters

curl "<API_URL>?param1=value1&param2=value2"

Parse JSON Responses with jq

1. Pretty Print JSON

curl -s <API_URL> | jq

2. Extract Specific Data

curl -s <API_URL> | jq '.key'

3. Extract Nested Data

curl -s <API_URL> | jq '.parentKey.childKey'

Automate with Shell Scripts

Create a Script:

  1. Open a file with a text editor:

    nano webhook.sh
  2. Add the script:

    #!/bin/bash
    
    WEBHOOK_URL="<YOUR_DISCORD_WEBHOOK>"
    MESSAGE="Hello from Termux!"
    
    curl -H "Content-Type: application/json" \
    -d "{\"content\":\"$MESSAGE\"}" \
    $WEBHOOK_URL
  3. Save and Exit (Ctrl + O, Enter, Ctrl + X).

  4. Make it executable:

    chmod +x webhook.sh
  5. Run the script:

    ./webhook.sh

Common Errors and Fixes

  1. 403 Forbidden Error:

    • Check your webhook URL or API token.
  2. Invalid JSON:

  3. Permission Denied:

    • Ensure the script has execute permissions:
      chmod +x script.sh

Here’s a comprehensive and advanced Termux cheat sheet designed for power users, covering system tasks, development, networking, scripting, hacking tools, and more.


1. Termux Basics

  • Update & Upgrade:
    pkg update && pkg upgrade
  • Install a Package:
    pkg install package_name
  • Search for a Package:
    pkg search keyword
  • Uninstall a Package:
    pkg uninstall package_name

2. File Management

  • List Files with Details:
    ls -lha
  • Copy Files:
    cp source destination
  • Move/Rename Files:
    mv old_name new_name
  • Find Files:
    find / -name "filename"
  • Extract Archives:
    • .tar.gz:
      tar -xzvf archive.tar.gz
    • .zip:
      unzip archive.zip

3. Networking & Internet

  • Download Files:
    wget -c URL
  • HTTP Requests:
    curl -X GET/POST URL
  • Network Tools:
    • Install tools like nmap and ping:
      pkg install nmap
      nmap -A target_ip
    • Check internet speed:
      pkg install speedtest-cli
      speedtest
  • SSH into a Remote Server:
    ssh user@host

4. Scripting and Automation

  • Create a Script:
    nano script.sh
  • Add Execute Permission:
    chmod +x script.sh
  • Run the Script:
    ./script.sh
  • Schedule Tasks (Cron Jobs):
    crontab -e
    Example Cron Entry:
    0 5 * * * /data/data/com.termux/files/home/script.sh

5. Development Tools

  • Programming Language Setup:

    • Python:
      pkg install python
      python3 script.py
    • Java:
      pkg install openjdk
      javac Program.java
      java Program
    • Node.js:
      pkg install nodejs
      node script.js
  • Version Control (Git):

    • Clone a Repository:
      git clone repo_url
    • Check Status:
      git status

6. System Monitoring

  • System Resources:
    top
  • Detailed Monitoring with htop:
    pkg install htop
    htop
  • Disk Usage:
    df -h
    du -sh *

7. Ethical Hacking Tools

Install hacking tools responsibly!

  • Metasploit:
    pkg install metasploit
    msfconsole
  • SQLMap:
    pkg install sqlmap
    sqlmap -u target_url
  • Wireshark CLI:
    pkg install wireshark
    tshark
  • John the Ripper:
    pkg install john
    john hashfile

8. Advanced Termux-Specific Commands

  • Clipboard:

    • Copy to clipboard:
      echo "text" | termux-clipboard-set
    • Retrieve clipboard:
      termux-clipboard-get
  • Microphone Recording:

    termux-microphone-record -f audio.wav
  • Sensor Data:

    termux-sensor -s TYPE

    Example:

    termux-sensor -s accelerometer
  • Battery Status:

    termux-battery-status

9. Package Management & Custom Repositories

  • List Installed Packages:
    pkg list-installed
  • Backup Installed Packages:
    dpkg --get-selections > backup.txt
  • Restore Packages:
    dpkg --set-selections < backup.txt
    apt-get dselect-upgrade

10. Fun and Miscellaneous

  • Matrix Effect:

    pkg install cmatrix
    cmatrix
  • Install Figlet for ASCII Art:

    pkg install figlet
    figlet "Hello, Termux!"
  • Install Fortune for Quotes:

    pkg install fortune
    fortune
  • Combine Fortune with Cowsay:

    pkg install cowsay
    fortune | cowsay

11. Troubleshooting and Debugging

  • Fix Package Issues:
    apt-get --fix-broken install
  • Check Logs:
    logcat

12. Aliases and Customization

  • Set an Alias:
    alias ll='ls -la'
  • Remove an Alias:
    unalias ll
  • Make Aliases Permanent: Edit the .bashrc file:
    nano ~/.bashrc
    Add your aliases, then reload:
    source ~/.bashrc

This cheat sheet should help you perform advanced tasks in Termux efficiently. For extremely advanced workflows, you can combine scripting, custom tools, and third-party APIs!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment