· FabLab Westharima Team · Documentation · 6 min read
Terminal Commands List (with Options & Examples) [Practical Focus]
A practical reference list of commonly used terminal commands with descriptions, main options, and usage examples. A practical command reference for Linux and macOS.
A practical reference list of commonly used terminal (shell) commands organized by description, main options, and usage examples. This guide focuses on the essentials you’ll need to quickly remember. It covers commands that work on both Linux and macOS, with additional helpful macOS-specific commands. For more detailed information, use man command-name or command --help.
Usage Tips
Safety first: For destructive commands like
rm -rf, always verify the target and path before executing. Use the-i(interactive/confirm) option to prevent accidental deletion.Use manual pages: Check
man command-nameorcommand --helpfor detailed information and options. Consult the manual first when you need help.Power of combination: Using pipes (
|) and redirects (>,>>) to chain commands together allows you to work more efficiently. Example:cat file.txt | grep "error" > errors.txtTab completion: Press
Tabwhile typing a command or filename to auto-complete. This saves time with long paths and complex names.Command history: Use arrow keys to navigate previous commands. Use
historyto see a list, and!nto re-execute a specific history entry.Wildcards: Use
*and?to specify multiple files at once. Example:ls *.txtInterrupt commands: Press
Ctrl + Cto stop a running command, orCtrl + Zto pause it.Command aliasing: Create shorter names for frequently used commands with
alias. Example:alias ll='ls -lAh'File permissions: Check permissions with
ls -l, and change them withchmodorchown.
Basic Operations / Navigation
| Command | Description | Main Options | Usage Example |
|---|---|---|---|
| pwd | Display current working directory | None | pwd (shows current path) |
| ls | List directory contents | -l: detailed listing -a: show hidden files -h: human-readable sizes | ls (simple list) ls -l (detailed list) ls -la (detailed including hidden) ls -lh (readable sizes) |
| cd | Change directory | -: previous directory ..: parent directory | cd /var/log (absolute path) cd .. (go to parent) cd - (return to previous) |
| clear | Clear screen | None | clear (clear display) |
| exit | Exit shell | None | exit (exit shell) |
File / Directory Operations
| Command | Description | Main Options | Usage Example |
|---|---|---|---|
| mkdir | Create directory | -p: create parent directories as needed | mkdir -p project/data/raw (creates all needed parent directories including data and project if they don’t exist) |
| rmdir | Remove empty directory | None | rmdir empty_dir (removes empty directory) |
| touch | Update timestamp / create file | None | touch new_file.txt (creates empty file) |
| cp | Copy file/directory | -r: recursive copy -i: confirm before overwrite -v: verbose output | cp -r src dst (recursively copy directory) |
| mv | Move/rename file/directory | -i: confirm before overwrite -v: verbose output | mv old.txt new.txt (rename file) |
| rm | Delete file/directory | -r: recursive delete -f: force delete -i: interactive/confirm | rm -rf build/ (⚠️ Force delete without confirmation. This is a very dangerous command - all specified files/directories are immediately deleted and cannot be recovered. Accidentally specifying wrong paths can render your system unusable. Always verify the path and contents before executing) |
| ln | Create hard/symbolic links | -s: create symbolic link | ln -s /path/to/original link_name (create symbolic link) |
What is a symbolic link? A symbolic link (symlink, soft link) is a special file that acts like a “shortcut” to another file or directory. If the target is moved or deleted, the link becomes broken, but symbolic links can be created across different filesystems. In contrast, a hard link only works within the same filesystem, and even if the original is deleted, other hard links still provide access to the content. Create symbolic links with
ln -sand hard links withln.
Search / Text Processing
| Command | Description | Main Options | Usage Example |
|---|---|---|---|
| cat | Concatenate and display files | -n: add line numbers | cat file1 file2 > all.txt (combine and save two files) |
| less | View content with paging | None | less large.log (view with page navigation) |
| head | Display first lines | -n: specify line count | head -n 20 file.txt (show first 20 lines) |
| tail | Display last lines | -n: specify line count -f: follow mode | tail -f /var/log/system.log (follow log file in real-time) |
| grep | Search using regex | -i: ignore case -v: invert match -r: recursive search | grep -ri "error" ./logs (case-insensitive recursive search) |
| wc | Count lines/words/bytes | -l: line count -w: word count -c: byte count | wc -l access.log (count lines only) |
| sort | Sort lines | -r: reverse order -n: numeric sort | sort -nr scores.txt (numeric descending sort) |
| uniq | Process duplicate lines | -c: count occurrences -d: show duplicates only | sort data.txt | uniq -c (count duplicate occurrences) |
| cut | Extract fields by delimiter | -d: delimiter -f: field numbers | cut -d ':' -f 1,7 /etc/passwd (extract columns 1 and 7) |
| find | Search for files by condition | -name: filename -type: file type -size: file size | find . -type f -name "*.log" (find all .log files) |
| xargs | Convert stdin to arguments | -n: argument count -P: parallel processes -I {}: placeholder | ls *.log | xargs -n1 gzip (compress each log sequentially) |
| sed | Stream editor for substitution | -e: expression -i: in-place edit -n: suppress output | sed -i '' 's/foo/bar/g' file.txt (replace foo with bar) |
| awk | Pattern processing and reporting | -F: field delimiter | awk -F, '{print $1, $3}' data.csv (print columns 1 and 3) |
What is a stream editor (sed)?
sedis called a “stream editor” and can automatically edit and transform text data from files or stdin according to rules you specify. For example, it can “replace all occurrences of a string,” “delete specific lines,” or “extract lines matching a pattern” without opening the file directly.
- Use it like
sed 's/search/replace/g' file.txt, wheresmeans “substitute”- Add the
-ioption to edit the file in-place (use-i.bakto create a backup)- Regular expressions are supported for complex pattern matching and bulk editing
Examples:
sed 's/foo/bar/g' file.txt… Replace all “foo” with “bar” and displaysed -i '' 's/foo/bar/g' file.txt… Directly edit file.txt to replace “foo” with “bar”
Process / System Information
| Command | Description | Main Options | Usage Example |
|---|---|---|---|
| ps | Display running processes | -e: all processes -f: full listing | ps -ef (show all processes in detail) |
| top | Monitor processes in real-time | None | top (monitor process activity) |
| kill | Terminate process | -9: force kill | kill -9 1234 (force terminate PID 1234) |
| uptime | Display uptime and load | None | uptime (show uptime and average load) |
| whoami | Display current username | None | whoami (show current username) |
| id | Display user/group IDs | None | id (show UID/GID) |
| df | Display filesystem usage | -h: human-readable -T: filesystem type | df -hT (show filesystems and space in readable format) |
| du | Display directory size | -h: human-readable -s: total only | du -sh ~/Downloads (show total size only) |
| chmod | Change file permissions | -R: recursive | chmod 755 script.sh (set permissions to 755) |
| chown | Change owner/group | -R: recursive | chown user:staff file.txt (change owner and group) |
Compression / Archive
| Command | Description | Main Options | Usage Example |
|---|---|---|---|
| tar | Create/extract archives | -c: create -x: extract -v: verbose -f: filename | tar -cvf archive.tar files/ (create archive) / tar -xvf archive.tar (extract archive) |
| zip | Compress in ZIP format | -r: recursive directory | zip -r archive.zip folder/ (recursively compress folder) |
| unzip | Extract ZIP | None | unzip archive.zip (extract ZIP) |
| gzip | Compress with gzip | -k: keep original | gzip file.txt (compress single file) |
| gunzip | Extract gzip | None | gunzip file.txt.gz (decompress gzip) |
Network / Remote
| Command | Description | Main Options | Usage Example |
|---|---|---|---|
| curl | Send HTTP request | -I: headers only -L: follow redirects -O/-o: save -X: HTTP method | curl -L -o file.tar.gz https://example.com/file.tar.gz (follow redirects and save) |
| wget | Download files | -O: output filename -r: recursive -c: continue partial | wget -O file.tar.gz https://example.com/file.tar.gz (download with specified name) |
| ssh | Remote login | -i: key file -p: port | ssh -i key.pem -p 2222 user@host (login with key and custom port) |
| scp | Transfer files with remote | -r: recursive -i: key -P: port | scp -i key.pem -P 2222 file user@host:/path/ (transfer with key and port) |
| which | Show executable path | None | which python3 (show path to python3) |
| alias | Define command alias | None | alias ll='ls -lah' (create ll shortcut) |
| history | Display command history | None | history (show history) |
Useful macOS Commands
| Command | Description | Main Options | Usage Example |
|---|---|---|---|
| open | Open with Finder/app | -a: specify app -R: show in Finder -t: default editor | open . (open current directory in Finder) open -a Finder . (specify Finder) open README.md (open with default app) |
| pbcopy | Copy to clipboard | None | echo "hello" | pbcopy (copy text to clipboard) |
| pbpaste | Paste from clipboard | None | pbpaste > clip.txt (save clipboard to file) |
| brew | Manage packages with Homebrew | install: install update: update definitions upgrade: upgrade packages list: list | brew install wget (install package) / brew upgrade (upgrade installed packages) |

![Terminal Launch, Usage, and Basic Commands [Beginner]](/_astro/mkdocs_material_guide_eyecatch.DfbB4An5.png)