Navigation
| pwd | Print current working directory |
| cd path | Change directory |
| cd .. | Go up one directory |
| cd ~ | Go to home directory |
| cd - | Go to previous directory |
| ls | List files and directories |
| ls -la | List all files with details |
| ls -lh | List with human-readable sizes |
| tree | Show directory tree |
Files & Directories
| touch file | Create an empty file |
| mkdir dir | Create a directory |
| mkdir -p a/b/c | Create nested directories |
| cp src dest | Copy file |
| cp -r src dest | Copy directory recursively |
| mv src dest | Move or rename file |
| rm file | Remove a file |
| rm -r dir | Remove directory recursively |
| ln -s target link | Create symbolic link |
Warning: rm -rf is permanent and cannot be undone. Always double-check paths before deleting.
Viewing & Editing Files
| cat file | Print file contents |
| less file | View file with scrolling |
| head -n 20 file | Show first 20 lines |
| tail -n 20 file | Show last 20 lines |
| tail -f file | Follow file in real time |
| nano file | Edit file with nano |
| vim file | Edit file with vim |
| wc -l file | Count lines in a file |
| diff file1 file2 | Compare two files |
Searching & Finding
| find . -name "*.txt" | Find files by name |
| find . -type d | Find directories only |
| grep "text" file | Search text in a file |
| grep -r "text" dir | Search recursively in directory |
| grep -i "text" file | Case-insensitive search |
| grep -n "text" file | Show line numbers |
| which command | Show path of a command |
| locate file | Fast search using index |
Permissions & Ownership
| chmod 755 file | Set file permissions |
| chmod +x file | Make file executable |
| chown user:group file | Change file owner |
| sudo command | Run as superuser |
| su user | Switch to another user |
Tip: Permission digits: r=4 w=2 x=1. So 755 = owner rwx, group r-x, others r-x.
Processes & System
| ps aux | List all running processes |
| top | Real-time process monitor |
| htop | Interactive process viewer |
| kill PID | Terminate a process by PID |
| kill -9 PID | Force kill a process |
| df -h | Show disk usage |
| du -sh dir | Size of a directory |
| free -h | Show memory usage |
| uname -a | System information |
| uptime | How long system has been running |
Piping & Redirection
| cmd > file | Redirect output to file (overwrite) |
| cmd >> file | Append output to file |
| cmd 2> file | Redirect errors to file |
| cmd &> file | Redirect all output to file |
| cmd1 | cmd2 | Pipe output of cmd1 to cmd2 |
| cmd | tee file | Output to screen and file |
| cmd | sort | Sort output |
| cmd | uniq | Remove duplicate lines |
| cmd | xargs cmd2 | Pass output as arguments |
Networking
| ping host | Test network connectivity |
| curl url | Fetch URL content |
| wget url | Download a file |
| ssh user@host | Connect via SSH |
| scp file user@host:path | Copy file over SSH |
| ifconfig | Show network interfaces |
| netstat -tuln | Show open ports |
| lsof -i :port | Find process using a port |
Shortcuts & History
| Ctrl+C | Cancel current command |
| Ctrl+Z | Suspend current process |
| Ctrl+D | Exit / logout |
| Ctrl+L | Clear screen |
| Ctrl+R | Search command history |
| Ctrl+A | Move cursor to line start |
| Ctrl+E | Move cursor to line end |
| Tab | Autocomplete |
| !! | Repeat last command |
| history | Show command history |
Compression & Archives
| tar -czf a.tar.gz dir | Create gzipped archive |
| tar -xzf a.tar.gz | Extract gzipped archive |
| tar -xf archive.tar | Extract tar archive |
| zip -r a.zip dir | Create zip archive |
| unzip a.zip | Extract zip archive |
| gzip file | Compress file |
| gunzip file.gz | Decompress file |
Environment & Variables
| echo $VAR | Print a variable |
| export VAR=value | Set environment variable |
| env | List all environment variables |
| alias name='cmd' | Create a shortcut alias |
| unalias name | Remove an alias |
| source ~/.bashrc | Reload shell config |
| echo $PATH | Show executable paths |
Tip: Add aliases and exports to ~/.bashrc or ~/.zshrc to make them permanent.
Misc & Useful
| man command | Show manual for a command |
| command --help | Quick help for a command |
| clear | Clear the terminal screen |
| date | Show current date & time |
| whoami | Show current username |
| hostname | Show system hostname |
| cal | Show a calendar |
| sleep 5 | Wait for 5 seconds |
| yes | command | Auto-confirm prompts |