# WSL / Ubuntu Command-Line Cheat Sheet ## Filesystem Navigation | Command | What it does | Example | |---------|-------------|---------| | `pwd` | Print the current directory (where you are) | `pwd` → `/home/alice` | | `ls` | List files and folders | `ls`, `ls -la` (detailed view) | | `cd ` | Change directory | `cd Documents`, `cd ~` (home), `cd ..` (up one) | | `mkdir ` | Create a new directory | `mkdir projects` | | `rmdir ` | Remove an **empty** directory | `rmdir old_folder` | ## File Operations | Command | What it does | Example | |---------|-------------|---------| | `touch ` | Create an empty file | `touch notes.txt` | | `cp ` | Copy a file | `cp notes.txt backup.txt` | | `mv ` | Move or rename a file | `mv notes.txt ~/Documents/` | | `rm ` | Delete a file (⚠️ no trash bin) | `rm temp.txt` | | `rm -r ` | Delete a folder and **everything inside** | `rm -r old_project/` | | `cat ` | Print a file's contents to the terminal | `cat notes.txt` | | `less ` | View a file page-by-page (press `q` to quit) | `less long_file.txt` | | `head ` | Show the first 10 lines | `head data.csv` | | `tail ` | Show the last 10 lines | `tail -n 20 data.csv` | | `nano ` | Edit a file in the terminal | `nano notes.txt` | ## Viewing & Finding | Command | What it does | Example | |---------|-------------|---------| | `file ` | Show what type of file something is | `file notes.txt` | | `find -name ` | Find files by name | `find ~ -name "*.md"` | | `grep ` | Search inside files | `grep "error" log.txt` | ## Permissions | Command | What it does | Example | |---------|-------------|---------| | `chmod ` | Change file permissions | `chmod +x script.sh` (make executable) | | `sudo ` | Run a command as admin (root) | `sudo apt update` | ## Package Management (apt) | Command | What it does | Example | |---------|-------------|---------| | `sudo apt update` | Refresh the list of available packages | Run before installing anything | | `sudo apt install ` | Install a package | `sudo apt install clang` | | `sudo apt upgrade` | Upgrade all installed packages | `sudo apt upgrade` | | `sudo apt remove ` | Uninstall a package | `sudo apt remove clang` | | `apt search ` | Search for a package | `apt search image editor` | ## Pipes & Redirection | Command | What it does | Example | |---------|-------------|---------| | `cmd1 \| cmd2` | Send output of `cmd1` into `cmd2` | `ls \| grep ".txt"` | | `>` | Redirect output to a file (overwrite) | `echo "hello" > hello.txt` | | `>>` | Redirect output to a file (append) | `echo "world" >> hello.txt` | ## WSL-Specific Tips - Your **Windows files** are under `/mnt/c/` — e.g. `/mnt/c/Users/YourName/Documents` - Your **Linux home** is at `/home/yourname` (type `~` as a shortcut) - Drag a file from Windows Explorer into the terminal to paste its WSL path - Use `explorer.exe .` to open the current Linux folder in Windows File Explorer ## Useful Shortcuts | Shortcut | What it does | |----------|-------------| | `Ctrl + C` | Cancel the current command | | `Ctrl + D` | Exit the terminal / close session | | `Tab` | Auto-complete file and folder names | | `↑` / `↓` | Scroll through command history | | `Ctrl + L` | Clear the screen | ## Quick Reference — First Steps ```bash # Where am I? pwd # What's in this folder? ls -la # Make a project folder and go inside mkdir my_project cd my_project # Create a file and edit it touch hello.txt nano hello.txt # Come back home cd ~ ```