OneLinersCommand workbench
Cheatsheets

Platform guide · macOS

macOS terminal cheat sheet

Useful macOS and Unix commands for Finder, Spotlight, Homebrew services, storage, networking, Git, and remote work — including BSD-specific variants.
60explained commands6practical sections100%concrete examples
08

System and identity

Capture the user, kernel, uptime, clock, and restart history of a Mac.

Show the current user and group identitiesidRead-only
Show system uptime and load averagesuptimeRead-only
Print kernel, architecture, and system informationuname -aRead-only
Print the current time in ISO 8601 formatmacOS variantdate -u +%Y-%m-%dT%H:%M:%SZRead-only
Show recent system reboot historylast reboot | head -10Read-only
Show the ten processes using the most memoryps aux | sort -nrk 4,4 | head -10Read-only
Show the ten processes using the most CPUps aux | sort -nrk 3,3 | head -10Read-only
List environment variables alphabeticallyenv | sortRead-only
12

Finder, Spotlight, and clipboard

Bridge terminal workflows with native macOS search, Finder, and clipboard tools.

Open a folder in Finderopen <folder>Read-only
Search the Spotlight index from the terminalmdfind <query>Read-only
Copy a file directly to the macOS clipboardpbcopy < <file>Read-only
Save the macOS clipboard to a filepbpaste > <file>caution
Show hidden files in Finderdefaults write com.apple.finder AppleShowAllFiles -bool true && killall Findercaution
Find files modified in the last 24 hoursfind . -type f -mtime -1Read-only
Search recursively for text with line numbersrg -n <search-text> <path>Read-only
Create a compressed tar archive from a foldertar -czf <archive-file> <folder>caution
Show a two-level directory treetree -L 2 <path>Read-only
Find empty files below the current directoryfind . -type f -empty -printRead-only
Delete empty directories below the current directoryfind . -type d -empty -deletedanger
Count files below the current directoryfind . -type f | wc -lRead-only
08

Files, text, and archives

Find recent content, search text, inspect directory trees, and create archives.

Search text with line numbers and surrounding contextrg -n -C <lines> --glob '<glob>' <pattern> <path>Read-only
List files inside a ZIP archiveunzip -l <archive-file>Read-only
Pretty-print and colorize a JSON documentjq . <file>Read-only
Extract active users from a JSON array as TSVjq -r '.[] | select(.active == true) | [.name, .email] | @tsv' <file>Read-only
Sum a numeric CSV column while skipping the headerawk -F, -v column=<column> 'NR>1 {sum += $column} END {printf "%.2f\n", sum}' <file>Read-only
Rank repeated lines by frequencysort <file> | uniq -c | sort -nr | head -<count>Read-only
Compare two directory trees without reading file bodiesdiff -qr <source> <destination>Read-only
List only matching files inside a compressed tar archivetar -tzf <archive-file> | rg <pattern>Read-only
08

Storage and filesystems

Measure free space, inode usage, and the paths consuming the most storage.

Show free disk space in human-readable unitsdf -hRead-only
Find the 20 largest files and folders heredu -ah . | sort -rh | head -20Read-only
Show filesystem inode usagedf -iRead-only
Refresh a folder size every two secondswatch -n 2 du -sh <folder>Read-only
Find deleted files that still consume disk spacesudo lsof -nP +L1 | sort -k7 -nr | head -<count>caution
List macOS disks and APFS containersdiskutil listRead-only
Inspect a macOS disk or volumediskutil info /Read-only
List APFS containers and volumesdiskutil apfs list | head -40Read-only
12

Network and DNS

Inspect listeners, DNS, routes, public addressing, and TLS from macOS.

List listening TCP ports and their processeslsof -iTCP -sTCP:LISTEN -n -PRead-only
Resolve a hostname to its IP addressdig +short <domain>Read-only
Print your current public IP addresscurl -s https://api.ipify.orgRead-only
Flush the macOS DNS cachesudo dscacheutil -flushcache && sudo killall -HUP mDNSRespondercaution
Show the default network routemacOS variantroute -n get defaultRead-only
Inspect a remote TLS certificateopenssl s_client -connect <host>:<port> -servername <host> </dev/null 2>/dev/null | openssl x509 -noout -subject -issuer -datesRead-only
Fetch only the HTTP response headerscurl -I <url>Read-only
Send four ICMP probes to a hostping -c 4 <host>Read-only
Trace the network path to a hosttraceroute <host>Read-only
Show Linux network interfaces and addressesmacOS variantifconfigRead-only
Measure HTTP response timingcurl -o /dev/null -s -w 'dns=%{time_namelookup}s connect=%{time_connect}s total=%{time_total}s\n' <url>Read-only
Check whether a TCP port accepts connectionsnc -vz <host> <port>Read-only
12

Services and developer workflow

Work with Homebrew services, Git changes, SSH configuration, and remote sync.

List services managed by Homebrewbrew services listRead-only
Show concise branch and working-tree statusgit status --short --branchRead-only
Summarize changed files and line counts in Gitgit diff --statRead-only
Show the effective OpenSSH client configuration for a hostssh -G <host> | sortRead-only
Copy a folder with progress and metadatarsync -avh --progress <source> <destination>caution
Find every log file below the current directoryfind . -type f -name '*.log' -printRead-only
Calculate the SHA-256 checksum of a filemacOS variantshasum -a 256 <file>Read-only
Add executable permission to a filechmod +x <file>caution
Print the latest Git commit in one compact linegit log -1 --onelineRead-only
Draw a compact graph of all Git branchesgit log --oneline --graph --decorate --allRead-only
List branches ordered by their latest commitgit branch --sort=-committerdateRead-only
Preview untracked files Git would removegit clean -ndRead-only