Linux Commands Cheat Sheet
Complete reference for the most useful terminal commands
File Operations
🏠 Create
mkdir name | Create a directory |
touch file | Create empty file |
cp file new | Copy file |
cp -r dir newdir | Copy directory recursively |
🔄 Move & Rename
mv file dir/ | Move file to directory |
mv old new | Rename file/directory |
mv -i file dir/ | Move with confirmation |
🗑️ Delete (Careful!)
rm file | Delete file (no undo!) |
rm -r dir | Delete directory + contents |
rm -i file | Delete with confirmation |
rmdir empty-folder | Delete an empty directory |
👁️ View Files
cat file | Display entire file |
less file | View with pagination (q to quit) |
head file | Show first 10 lines |
tail file | Show last 10 lines |
tail -f file | Watch file in real-time |
nano file | Open a simple text editor |
wc -l file | Count the lines in a file |
Search & Find
📂 Find Files
find . -name "*.txt" | Find all .txt files |
find . -name "*report*" | Find files with "report" in name |
find . -type d | Find all directories |
find . -size +1M | Find files larger than 1MB |
🔎 Search Inside Files
grep "word" file | Search for text in file |
grep -r "word" dir/ | Search recursively in directory |
grep -i "word" file | Case-insensitive search |
grep -n "word" file | Show line numbers |
Installing Software
| Command | What It Does |
|---|---|
sudo apt update | Refresh the package list before installing things |
sudo apt upgrade | Install available updates |
sudo apt install package | Install a program |
sudo apt remove package | Uninstall a program |
sudo apt autoremove | Clean up packages you no longer need |
apt search package | Search for a package by name |
apt show package | See details about a package |
System Commands
| Command | What It Does |
|---|---|
date | Show current date and time |
cal | Show calendar |
whoami | Show current username |
uname -a | Show system information |
df -h | Show disk space (human readable) |
du -sh */ | Show directory sizes |
free -h | Show memory and swap usage |
top | Live view of running processes |
htop | Interactive process viewer |
ps aux | List running processes |
uptime | Show how long the machine has been running |
lsb_release -a | Show Ubuntu version details |
history | Show command history |
man command | Show manual for command |
command --help | Quick help for command |
Networking
🔌 Connection Basics
ip a | Show IP addresses and network interfaces |
ping host | Test whether you can reach a host |
curl url | Fetch a web page or API response |
wget url | Download a file from the web |
🖥️ Remote Access
ssh user@host | Connect to another machine |
scp file user@host:/path | Copy a file to another machine |
which program | Show where a command lives |
nslookup domain | Look up a domain's IP address |
File Permissions
Understanding ls -la Output
-rwxr-xr-- 1 user group 1234 Jan 15 10:30 script.sh
Position 1: File Type
-= Regular filed= Directoryl= Link
Positions 2-10: Permissions
r= Readw= Writex= Execute-= No permission
Permission Groups
- 2-4: Owner
- 5-7: Group
- 8-10: Others
| Command | Description |
|---|---|
chmod +x file | Make file executable |
chmod 755 file | Owner: rwx, Group: r-x, Others: r-x |
chmod 644 file | Owner: rw-, Group: r--, Others: r-- |
chown user file | Change file owner |
Keyboard Shortcuts & Handy Patterns
⌨️ Shortcuts
Tab | Auto-complete a command or filename |
Ctrl + C | Stop the current command |
Ctrl + L | Clear the screen |
Ctrl + R | Search command history |
↑ / ↓ | Scroll through previous commands |
🔗 Pipes & Redirects
cmd | less | Scroll through long output |
cmd | grep word | Filter output for a word |
cmd > file | Save output to a file |
cmd >> file | Append output to a file |
cmd1 && cmd2 | Run the second command only if the first succeeds |
Quick Reference Card
Navigation
pwd- Where am I?ls- List filescd dir- Change directorycd ..- Go upcd ~- Home
Files
mkdir- Create foldertouch- Create filecp- Copymv- Move/Renamerm- Delete
View
cat- Show fileless- Page throughhead- First 10 linestail- Last 10 linesgrep- Search
🎯 Need Help?
Stuck on a command? Not sure what to do next? The fastest way to get unstuck is to ask Claude. Just describe what you're trying to do or paste the error.
Example 1: Paste an error
"I got this error: [paste error message] What does it mean?"
Example 2: Screenshot
"This isn't working as expected [attach screenshot]"
Example 3: Plain language
"I need to find all files modified in the last 24 hours"
No shame in asking. Claude can see your screen, understand context, and give you the exact command you need.