Command Line Cheat Sheet
Free terminal cheat sheet: navigation, file management, grep, pipes, redirects, and process commands at a glance.
Navigation
| Concept | Syntax | Example |
|---|---|---|
| Where am I? Prints the current directory path. | pwd | pwd → /home/ada/projects |
| List files -l long format, -a includes hidden files (dotfiles). | ls -la | ls -la |
| Change directory cd .. goes up one level; plain cd goes home. | cd <path> | cd projects/app |
| Find files Searches recursively from the given directory. | find <dir> -name <pattern> | find . -name "*.js" |
Learn it in a lesson: File System Navigation · Finding Files with find and xargs
Files & Folders
| Concept | Syntax | Example |
|---|---|---|
| Create -p creates the whole nested path at once. | touch <file> / mkdir -p <dir> | mkdir -p src/components |
| Copy / Move -r is needed to copy directories. mv also renames. | cp -r / mv | cp -r src backup/ |
| Delete ⚠️ There is no recycle bin — rm is permanent. | rm <file> / rm -r <dir> | rm -r old-build |
| View a file less scrolls; tail -f follows a growing log live. | cat, less, head, tail | tail -n 50 app.log |
Learn it in a lesson: File Management Commands
Search & Text
| Concept | Syntax | Example |
|---|---|---|
| Search in files -n shows line numbers, -i ignores case. | grep -r "text" <dir> | grep -rn "TODO" src/ |
| Pipes Sends one command's output into the next — the shell's superpower. | cmd1 | cmd2 | history | grep git |
| Redirect output 2>&1 sends errors to the same place as normal output. | > overwrite, >> append | node app.js > out.log 2>&1 |
| Count things Counts lines — combine with pipes to count anything. | wc -l | ls | wc -l |
Learn it in a lesson: Pipes and Redirection · Text Processing with grep, sed, awk · Redirection and File Descriptors
Power Moves
| Concept | Syntax | Example |
|---|---|---|
| Stop a program Ctrl+Z suspends instead; fg resumes it. | Ctrl+C | (stops the running process) |
| Rerun & history !! repeats the last command — handy after forgetting sudo. | history, !!, ↑ | sudo !! |
| Permissions Makes a script executable so ./deploy.sh runs. | chmod +x <file> | chmod +x deploy.sh |
| Processes Find a process and stop it; -9 is the forceful version. | ps aux | grep <name>, kill <pid> | kill -9 12345 |
Learn it in a lesson: Process Management · Permissions and Users
Finding Things
| Concept | Syntax | Example |
|---|---|---|
| Find files by name Quote the pattern or the shell expands it before find sees it. | find . -name '*.log' | find . -name '*.log' -mtime -1 |
| Search inside files -r recurses, -n gives line numbers, -i ignores case. | grep -rn 'text' . | grep -rn 'TODO' src/ |
| Only matching part | grep -o | grep -o 'v[0-9.]*' file |
| Which command is this | which / type | which python3 |
| Search history | Ctrl+R | Ctrl+R then type part of an old command |
Learn it in a lesson: Finding Files with find and xargs · Text Processing with grep, sed, awk · Environment Variables
Pipes & Redirection
| Concept | Syntax | Example |
|---|---|---|
| Pipe Sends a's stdout into b's stdin. | a | b | ps aux | grep node |
| Write to a file > truncates the file, >> appends. The difference has cost people work. | > file | >> file | echo hi > out.txt |
| Errors too stderr is a separate stream and is NOT piped unless you redirect it. | 2>&1 | make 2>&1 | tee build.log |
| Discard output | > /dev/null | command > /dev/null 2>&1 |
| See and save | tee | npm test | tee test.log |
| Count lines | wc -l | grep -c 'error' log.txt |
Learn it in a lesson: Pipes and Redirection · Redirection and File Descriptors
Text Processing
| Concept | Syntax | Example |
|---|---|---|
| Pick a column | cut -d',' -f2 | awk '{print $2}' | awk -F',' '{print $2}' data.csv |
| Replace text Add -i to edit the file in place — and make a backup first. | sed 's/old/new/g' | sed 's/foo/bar/g' file.txt |
| Sort and dedupe uniq only removes ADJACENT duplicates, which is why sort comes first. | sort | uniq -c | sort words.txt | uniq -c | sort -rn | head |
| First or last lines -f follows the file as it grows. | head -n / tail -n | tail -f app.log |
Learn it in a lesson: Text Processing with grep, sed, awk
Permissions & Jobs
| Concept | Syntax | Example |
|---|---|---|
| Make executable | chmod +x file | chmod +x deploy.sh |
| Run in the background | command & | npm run dev & |
| Keep running after logout | nohup command & | nohup ./worker.sh & |
| Stop a command | Ctrl+C | Ctrl+C sends SIGINT to the foreground job |
| Chain on success && only runs b if a succeeded; ; runs b either way. | a && b | npm test && npm run build |
Learn it in a lesson: Process Management · Permissions and Users · Pipes and Redirection