Commands
Categories

1. Basic Commands

whoami

Prints the current logged-in username.

whoami
pwd

Displays the current working directory.

pwd
ls

Lists files and folders within a directory.

ls [flag] [directory_path]
  • -l: Long list showing permissions, owner, size, and date.
  • -a: List all files, including hidden ones (starting with .).
  • -i: Displays the inode number (memory address ID).
  • -h: Human readable sizes.
Eg: ls -la
cd

Change the current directory.

cd [path]
  • ~: Go to home directory.
  • ..: Go up one level.
  • /: Go to root directory.
clear

Clears the terminal screen.

clear
history

Shows all commands entered till date in the terminal.

  • Use !n to execute the command number n from history.
  • Combine with grep to find specific past commands.
Eg: !100
man

Displays the manual for the given syntax.

man [command]

Press 'q' to quit from the manual mode.

2. File Operations

mkdir

Create a new directory (folder).

mkdir [folder_name]

Note: md can sometimes be used as a shorthand.

cp

Copy files or directories.

cp [flags] /source/* /destination/
  • -r: Copy recursively (needed for directories).
  • -v: Verbose (shows what is being copied).
  • -u: Only copy if source is newer.
  • -p: Preserve timestamps and permissions.
mv

Move or rename files/directories.

mv [source] [destination]
rm

Removes files or directories permanently.

rm [flags] [file_name]
  • -r: Recursive delete (required for folders).
  • -f: Force delete without prompt.
  • --: Treats everything after as filename (useful if filename starts with -).
Eg: rm -- -filename.txt
shred

Overwrites the specified file's data to prevent recovery.

shred [flags] [file_name]
  • -n: Overwrite N times (default 3).
  • -z: Add final overwrite with zeros.
  • -u: Truncate and remove file after overwriting.
Eg: shred -n 5 -zu file.txt

3. Text Processing

cat

Displays the contents of a file.

cat [file_name]
nano

Basic terminal text editor.

nano [file_name]

Press Ctrl+O to save and Ctrl+X to exit.

vim

Advanced text editor.

vim [file_name]
tail

Outputs the last part of files.

tail -f [log_file]

Use -f to follow appended data (great for monitoring logs).

less

Allows forward and backward movement through the file.

less [file]

Press 'q' to quit.

grep

Searches for a pattern in files.

grep [flags] "pattern" [file]
  • -r: Recursive search.
  • -i: Case insensitive.
  • -c: Count matches.
  • -n: Show line numbers.
  • -E: Extended regex (e.g., for OR operator).
Eg: grep -rn "error" /var/log
sed

Stream editor for filtering and transforming text.

sed [flags] 's/search/replace/g' filename
  • -i: Edit file in-place (omit to just preview).
  • s: Substitute.
  • g: Global replacement (all occurrences in line).
Eg: sed -i 's/foo/bar/g' config.txt
awk

Used for logical searching and text processing (column manipulation).

awk '{print $1}' filename

Prints first column of the file.

tr

Translate or delete characters. Simpler than sed for character replacement.

tr "old" "new" < filename
perl

Powerful alternative to sed, useful for complex regex and indentation.

perl -i -pe 's/old/new/g' file.txt
Eg: perl -i -pe 's/src=".*?"/src="new"/g' file.txt
sort

Sorts lines of text files.

sort -h filename

-h enables human-numeric sort (e.g., 2K > 1G).

seq

Prints a sequence of numbers.

seq 1 10

5. System & Permissions

chmod

Change permission of file or directory.

chmod [permission] [file]
  • +x: Make executable.
  • -w: Remove write permission.
Eg: chmod +x script.sh
alias

Create a shortcut for a command.

alias [name]='[command]'

To make permanent, edit ~/.bashrc.

Eg: alias lst='tail -50'
shutdown

Schedule a power off.

sudo shutdown [flags] [time]
  • -h now: Shutdown immediately.
  • -r now: Reboot immediately.
  • -c: Cancel a scheduled shutdown.
lsof

List open files (used to check running ports).

lsof -i:[port_number]
upower

Display battery health and status.

upower -i /org/freedesktop/UPower/devices/battery_BAT0

Check capacity: below 50% is considered poor.

zip

Package and compress files (with encryption).

zip -er archive.zip folder/

-e encrypts, -r recursive.

unzip

Extract compressed zip files.

unzip archive.zip
gpg

GNU Privacy Guard (File encryption).

gpg -c [file]

Decrypt with: gpg -d file.gpg > file.

6. Network

nmcli

Command-line network manager.

  • device show: Shows IP, DNS info.
  • device wifi show-password: Shows current WiFi password.
wget

Download files from the web.

wget [url]
curl

Transfer data from or to a server.

curl [url]
rsync

Remote sync (efficiently copies/syncs files).

rsync -avz /src user@remote:/dest
  • -a: Archive mode (preserves permissions).
  • -v: Verbose.
  • -z: Compress during transfer.

7. Disk & Memory

df

Report file system disk space usage.

df -h

-h for human readable format.

du

Estimate file space usage.

du -sh [directory]

-s summary, -h human readable.

lsblk

List block devices (disks and partitions).

lsblk

8. Package Management

apt

Debian/Ubuntu package manager.

  • update: Reload package index.
  • upgrade [pkg]: Install newer versions.
  • install [pkg]: Install a package.
  • search [pkg]: Search for a package.
  • list --installed: List installed packages.
Eg: sudo apt update && sudo apt upgrade code
snap

Package manager for snap packages.

  • list --all: List all snaps.
  • remove [pkg]: Remove package.

9. Media & Conversions

ffmpeg

Tool for audio/video/image conversion.

  • Convert format: ffmpeg -i input.mp4 output.avi
  • Extract audio: ffmpeg -i video.mp4 -b:a 192k audio.mp3
img2pdf

Convert images to PDF.

img2pdf -o out.pdf *.jpg

Add --pagesize A4 to force A4 size.

pdftk

PDF Toolkit (merge, split, rotate).

pdftk in1.pdf in2.pdf cat output out.pdf

Merges in1 and in2 into out.pdf.

yt-dlp

Downloader for YouTube and other media sites.

yt-dlp -x --audio-format mp3 [URL]

Download best video: yt-dlp -f best [URL].

10. Tools & Utilities

python3

Python command line utility (quick server).

python3 -m http.server 8000

Creates a local web server at port 8000.

wormhole

Secure file transfer.

wormhole send [file]

Receiver uses: wormhole receive [code].

qrencode

Generate QR codes in terminal.

qrencode -t ansiutf8 "text"