Essential commands for navigating and working with the Linux command line
| mkdir name | Create a new directory |
| mkdir -p a/b/c | Create nested directories |
| touch file.txt | Create empty file |
| echo "text" > file | Create file with content (overwrites!) |
| echo "text" >> file | Append text to file |
| cat file | Display entire file contents |
| less file | View file page by page (q to quit) |
| head file | Show first 10 lines |
| head -n 5 file | Show first 5 lines |
| tail file | Show last 10 lines |
| tail -n 20 file | Show last 20 lines |
| wc -l file | Count lines in file |
| cp src dest | Copy file |
| cp -r src dest | Copy directory recursively |
| mv old new | Move or rename file/folder |
| rm file | Delete file (permanent!) |
| rm -i file | Delete with confirmation |
| rm -r folder | Delete folder and contents |
| rmdir folder | Delete empty directory |
| sudo command | Run as administrator |
| sudo apt update | Update package list |
| sudo apt install pkg | Install software |
| sudo apt remove pkg | Remove software |
| man command | Show manual for command |
| clear | Clear the terminal screen |
| history | Show command history |
| exit | Close terminal session |
| cmd1 | cmd2 | Pipe output to another command |
| cmd > file | Redirect output to file (overwrite) |
| cmd >> file | Append output to file |
| cmd1 && cmd2 | Run cmd2 if cmd1 succeeds |
| cmd1 ; cmd2 | Run both commands |
| sort file | Sort lines alphabetically |
| uniq file | Remove duplicate lines |
| grep "text" file | Search for text inside a file |
| grep -i "text" file | Case-insensitive search |
| grep -r "text" dir | Search recursively in directory |
| grep -n "text" file | Show line numbers |
| find /path -name "*.txt" | Find files by name pattern |
| find /path -type d | Find directories only |
| find /path -mtime -7 | Find files modified in last 7 days |
| ps | Show your running processes |
| ps aux | Show ALL system processes |
| top | Real-time process monitor (q to quit) |
| kill PID | Terminate process by ID |
| kill -9 PID | Force kill stubborn process |
| killall name | Kill all processes by name |
| bg / fg | Background / foreground a job |
In the Ubuntu terminal, use the Control key (not Command). These work once you're inside the terminal.
rm permanently deletes files - there is NO undo, NO recycle bin!rm -rf / or rm -rf ~ - this destroys everything!rm -i when unsure (asks for confirmation)sudo sparingly - only when actually neededsudo su - creates unrestricted admin shell> overwrites files without warning - use >> to append safely