Linux Command Quick Reference
Commands
Categories
1. Basic Commands
Prints the current logged-in username.
whoami
Displays the current working directory.
pwd
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.
Change the current directory.
cd [path]
- ~: Go to home directory.
- ..: Go up one level.
- /: Go to root directory.
Clears the terminal screen.
clear
Shows all commands entered till date in the terminal.
- Use !n to execute the command number n from history.
- Combine with
grepto find specific past commands.
Displays the manual for the given syntax.
man [command]
Press 'q' to quit from the manual mode.
2. File Operations
Create a new directory (folder).
mkdir [folder_name]
Note: md can sometimes be used as a shorthand.
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.
Move or rename files/directories.
mv [source] [destination]
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 -).
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.
3. Text Processing
Displays the contents of a file.
cat [file_name]
Basic terminal text editor.
nano [file_name]
Press Ctrl+O to save and Ctrl+X to exit.
Advanced text editor.
vim [file_name]
Outputs the first part of files (default 10 lines).
head -n [number] [file]
Outputs the last part of files.
tail -f [log_file]
Use -f to follow appended data (great for monitoring logs).
Allows forward and backward movement through the file.
less [file]
Press 'q' to quit.
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).
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).
Used for logical searching and text processing (column manipulation).
awk '{print $1}' filename
Prints first column of the file.
Translate or delete characters. Simpler than sed for character replacement.
tr "old" "new" < filename
Powerful alternative to sed, useful for complex regex and indentation.
perl -i -pe 's/old/new/g' file.txt
Sorts lines of text files.
sort -h filename
-h enables human-numeric sort (e.g., 2K > 1G).
Prints a sequence of numbers.
seq 1 10
4. Searching
Search for files in a directory hierarchy.
find [path] [options] [expression]
- -name "pattern": Exact name (case-sensitive).
- -iname "pattern": Case-insensitive name.
- -type d: Find directories only.
- -type f: Find files only.
- -maxdepth N: Limit search depth.
5. System & Permissions
Change permission of file or directory.
chmod [permission] [file]
- +x: Make executable.
- -w: Remove write permission.
Create a shortcut for a command.
alias [name]='[command]'
To make permanent, edit ~/.bashrc.
Schedule a power off.
sudo shutdown [flags] [time]
- -h now: Shutdown immediately.
- -r now: Reboot immediately.
- -c: Cancel a scheduled shutdown.
List open files (used to check running ports).
lsof -i:[port_number]
Display battery health and status.
upower -i /org/freedesktop/UPower/devices/battery_BAT0
Check capacity: below 50% is considered poor.
Package and compress files (with encryption).
zip -er archive.zip folder/
-e encrypts, -r recursive.
Extract compressed zip files.
unzip archive.zip
GNU Privacy Guard (File encryption).
gpg -c [file]
Decrypt with: gpg -d file.gpg > file.
6. Network
Command-line network manager.
- device show: Shows IP, DNS info.
- device wifi show-password: Shows current WiFi password.
Download files from the web.
wget [url]
Transfer data from or to a server.
curl [url]
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
Report file system disk space usage.
df -h
-h for human readable format.
Estimate file space usage.
du -sh [directory]
-s summary, -h human readable.
List block devices (disks and partitions).
lsblk
8. Package Management
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.
Package manager for snap packages.
- list --all: List all snaps.
- remove [pkg]: Remove package.
9. Media & Conversions
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
Convert images to PDF.
img2pdf -o out.pdf *.jpg
Add --pagesize A4 to force A4 size.
PDF Toolkit (merge, split, rotate).
pdftk in1.pdf in2.pdf cat output out.pdf
Merges in1 and in2 into out.pdf.
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
Python command line utility (quick server).
python3 -m http.server 8000
Creates a local web server at port 8000.
Secure file transfer.
wormhole send [file]
Receiver uses: wormhole receive [code].
Generate QR codes in terminal.
qrencode -t ansiutf8 "text"