· 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-name or command --help for 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.txt

  • Tab completion: Press Tab while 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 history to see a list, and !n to re-execute a specific history entry.

  • Wildcards: Use * and ? to specify multiple files at once. Example: ls *.txt

  • Interrupt commands: Press Ctrl + C to stop a running command, or Ctrl + Z to 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 with chmod or chown.


Basic Operations / Navigation

CommandDescriptionMain OptionsUsage Example
pwdDisplay current working directoryNonepwd (shows current path)
lsList directory contents-l: detailed listing -a: show hidden files -h: human-readable sizesls (simple list) ls -l (detailed list) ls -la (detailed including hidden) ls -lh (readable sizes)
cdChange directory-: previous directory ..: parent directorycd /var/log (absolute path) cd .. (go to parent) cd - (return to previous)
clearClear screenNoneclear (clear display)
exitExit shellNoneexit (exit shell)

File / Directory Operations

CommandDescriptionMain OptionsUsage Example
mkdirCreate directory-p: create parent directories as neededmkdir -p project/data/raw (creates all needed parent directories including data and project if they don’t exist)
rmdirRemove empty directoryNonermdir empty_dir (removes empty directory)
touchUpdate timestamp / create fileNonetouch new_file.txt (creates empty file)
cpCopy file/directory-r: recursive copy -i: confirm before overwrite -v: verbose outputcp -r src dst (recursively copy directory)
mvMove/rename file/directory-i: confirm before overwrite -v: verbose outputmv old.txt new.txt (rename file)
rmDelete file/directory-r: recursive delete -f: force delete -i: interactive/confirmrm -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)
lnCreate hard/symbolic links-s: create symbolic linkln -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 -s and hard links with ln.


Search / Text Processing

CommandDescriptionMain OptionsUsage Example
catConcatenate and display files-n: add line numberscat file1 file2 > all.txt (combine and save two files)
lessView content with pagingNoneless large.log (view with page navigation)
headDisplay first lines-n: specify line counthead -n 20 file.txt (show first 20 lines)
tailDisplay last lines-n: specify line count -f: follow modetail -f /var/log/system.log (follow log file in real-time)
grepSearch using regex-i: ignore case -v: invert match -r: recursive searchgrep -ri "error" ./logs (case-insensitive recursive search)
wcCount lines/words/bytes-l: line count -w: word count -c: byte countwc -l access.log (count lines only)
sortSort lines-r: reverse order -n: numeric sortsort -nr scores.txt (numeric descending sort)
uniqProcess duplicate lines-c: count occurrences -d: show duplicates onlysort data.txt | uniq -c (count duplicate occurrences)
cutExtract fields by delimiter-d: delimiter -f: field numberscut -d ':' -f 1,7 /etc/passwd (extract columns 1 and 7)
findSearch for files by condition-name: filename -type: file type -size: file sizefind . -type f -name "*.log" (find all .log files)
xargsConvert stdin to arguments-n: argument count -P: parallel processes -I {}: placeholderls *.log | xargs -n1 gzip (compress each log sequentially)
sedStream editor for substitution-e: expression -i: in-place edit -n: suppress outputsed -i '' 's/foo/bar/g' file.txt (replace foo with bar)
awkPattern processing and reporting-F: field delimiterawk -F, '{print $1, $3}' data.csv (print columns 1 and 3)

What is a stream editor (sed)? sed is 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, where s means “substitute”
  • Add the -i option to edit the file in-place (use -i.bak to 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 display
  • sed -i '' 's/foo/bar/g' file.txt … Directly edit file.txt to replace “foo” with “bar”

Process / System Information

CommandDescriptionMain OptionsUsage Example
psDisplay running processes-e: all processes -f: full listingps -ef (show all processes in detail)
topMonitor processes in real-timeNonetop (monitor process activity)
killTerminate process-9: force killkill -9 1234 (force terminate PID 1234)
uptimeDisplay uptime and loadNoneuptime (show uptime and average load)
whoamiDisplay current usernameNonewhoami (show current username)
idDisplay user/group IDsNoneid (show UID/GID)
dfDisplay filesystem usage-h: human-readable -T: filesystem typedf -hT (show filesystems and space in readable format)
duDisplay directory size-h: human-readable -s: total onlydu -sh ~/Downloads (show total size only)
chmodChange file permissions-R: recursivechmod 755 script.sh (set permissions to 755)
chownChange owner/group-R: recursivechown user:staff file.txt (change owner and group)

Compression / Archive

CommandDescriptionMain OptionsUsage Example
tarCreate/extract archives-c: create -x: extract -v: verbose -f: filenametar -cvf archive.tar files/ (create archive) / tar -xvf archive.tar (extract archive)
zipCompress in ZIP format-r: recursive directoryzip -r archive.zip folder/ (recursively compress folder)
unzipExtract ZIPNoneunzip archive.zip (extract ZIP)
gzipCompress with gzip-k: keep originalgzip file.txt (compress single file)
gunzipExtract gzipNonegunzip file.txt.gz (decompress gzip)

Network / Remote

CommandDescriptionMain OptionsUsage Example
curlSend HTTP request-I: headers only -L: follow redirects -O/-o: save -X: HTTP methodcurl -L -o file.tar.gz https://example.com/file.tar.gz (follow redirects and save)
wgetDownload files-O: output filename -r: recursive -c: continue partialwget -O file.tar.gz https://example.com/file.tar.gz (download with specified name)
sshRemote login-i: key file -p: portssh -i key.pem -p 2222 user@host (login with key and custom port)
scpTransfer files with remote-r: recursive -i: key -P: portscp -i key.pem -P 2222 file user@host:/path/ (transfer with key and port)
whichShow executable pathNonewhich python3 (show path to python3)
aliasDefine command aliasNonealias ll='ls -lah' (create ll shortcut)
historyDisplay command historyNonehistory (show history)

Useful macOS Commands

CommandDescriptionMain OptionsUsage Example
openOpen with Finder/app-a: specify app -R: show in Finder -t: default editoropen . (open current directory in Finder) open -a Finder . (specify Finder) open README.md (open with default app)
pbcopyCopy to clipboardNoneecho "hello" | pbcopy (copy text to clipboard)
pbpastePaste from clipboardNonepbpaste > clip.txt (save clipboard to file)
brewManage packages with Homebrewinstall: install update: update definitions upgrade: upgrade packages list: listbrew install wget (install package) / brew upgrade (upgrade installed packages)

Back to Blog

Related Posts

View All Posts →
Markdown | Guide & Cheat Sheet

Markdown | Guide & Cheat Sheet

A comprehensive English guide covering Markdown basics, advanced features, practical considerations, and accessibility support. A complete cheat sheet for beginners and advanced users alike.