Last active
April 3, 2026 14:36
-
-
Save eplt/027c99215e37a3a138c32b19a944b05d to your computer and use it in GitHub Desktop.
macOS Cheatsheet - Commonly used commands for my macOS Setup
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # macOS Cheatsheet — Commonly Used Commands for macOS Tahoe (26) Setup | |
| > Last updated: April 2026 · Tested on macOS Tahoe 26.4 (Apple Silicon) | |
| --- | |
| ## Table of Contents | |
| - [1. Automation \& Scheduling](#1-automation--scheduling) | |
| - [2. System Management](#2-system-management) | |
| - [3. Performance \& Monitoring](#3-performance--monitoring) | |
| - [4. File \& Batch Operations](#4-file--batch-operations) | |
| - [5. Development \& DevOps](#5-development--devops) | |
| - [6. Security, Network \& Code Signing](#6-security-network--code-signing) | |
| - [7. Reference \& Quick Tools](#7-reference--quick-tools) | |
| - [8. Apple Silicon Specific](#8-apple-silicon-specific) | |
| - [9. Scripting \& Automation](#9-scripting--automation) | |
| - [10. Data Processing \& Regex](#10-data-processing--regex) | |
| - [11. Miscellaneous](#11-miscellaneous) | |
| - [Summary of Key Changes for macOS Tahoe (26)](#summary-of-key-changes-for-macos-tahoe-26) | |
| --- | |
| ## 1. Automation & Scheduling | |
| ### Classic Cron (still works, but officially deprecated by Apple in favor of launchd) | |
| ```bash | |
| # Edit your crontab using nano as the editor | |
| env EDITOR=nano crontab -e | |
| # List all scheduled cron jobs for the current user | |
| crontab -l | |
| # Remove ALL scheduled cron jobs — use with caution! | |
| crontab -r | |
| # ── Example: open news sites in Safari every day at 7:00 AM ── | |
| # Format: minute hour day-of-month month day-of-week command | |
| # 0 7 * * * = "at 07:00, every day" | |
| 0 7 * * * open -a Safari http://www.bbc.com/news | |
| 0 7 * * * open -a Safari http://money.cnn.com | |
| 0 7 * * * open -a Safari https://flipboard.com/section/technology-c5o31di9kg9ea7p6 | |
| 0 7 * * * open -a Safari https://www.macrumors.com | |
| 0 7 * * * open -a 'Brave Browser' http://www.bbc.com | |
| # Open a URL in a brand-new window (not a new tab) in Chrome or Brave | |
| open -na "Google Chrome" --args --new-window "https://www.bbc.com" | |
| open -na "Brave Browser" --args --new-window "https://www.bbc.com" | |
| ``` | |
| ### Modern Scheduling with launchd (Apple's recommended approach) | |
| Create a plist file at `~/Library/LaunchAgents/com.user.safari-opener.plist`. See [Apple's launchd documentation](https://developer.apple.com/library/archive/documentation/MacOSX/Conceptual/BPSystemStartup/Chapters/CreatingLaunchdJobs.html) for the full plist schema. | |
| ```bash | |
| # ── Legacy syntax (still works but prints deprecation warnings) ── | |
| launchctl load ~/Library/LaunchAgents/com.user.safari-opener.plist | |
| launchctl unload ~/Library/LaunchAgents/com.user.safari-opener.plist | |
| # ── Modern syntax (preferred on macOS Tahoe) ── | |
| # "gui/$(id -u)" targets the current user's GUI domain | |
| launchctl bootstrap gui/$(id -u) ~/Library/LaunchAgents/com.user.safari-opener.plist | |
| launchctl bootout gui/$(id -u)/com.user.safari-opener | |
| # Check if your agent is loaded | |
| launchctl list | grep safari-opener | |
| # Print detailed info including last exit status and error messages | |
| launchctl print gui/$(id -u)/com.user.safari-opener | |
| ``` | |
| ### Shortcuts Automations (NEW in macOS Tahoe) | |
| macOS Tahoe introduced **Shortcuts Automations**, which can trigger shortcuts based on events like time of day, files arriving in a folder, connecting an external display, Wi-Fi changes, and more — all without writing code. Open **Shortcuts.app → Automations** tab to explore triggers. | |
| ```bash | |
| # You can also run any shortcut from Terminal: | |
| shortcuts run "My Shortcut Name" | |
| # List all available shortcuts | |
| shortcuts list | |
| ``` | |
| ### File/Folder Change Monitoring | |
| ```bash | |
| # fswatch monitors file system changes in real time — great for dev workflows | |
| brew install fswatch | |
| # Echo a message whenever anything in ~/Downloads changes | |
| fswatch -o ~/Downloads | xargs -n1 -I {} echo "File changed in Downloads" | |
| # Practical example: auto-run a build script when source files change | |
| fswatch -o ./src | xargs -n1 -I {} make build | |
| ``` | |
| --- | |
| ## 2. System Management | |
| ### Change Screenshot Location & Format | |
| ```bash | |
| # Method 1 (Terminal): change screenshot save folder | |
| # NOTE: on macOS Mojave+, "killall SystemUIServer" is no longer needed for this. | |
| # The defaults write alone usually takes effect immediately (or after a logout). | |
| defaults write com.apple.screencapture location ~/Screenshots | |
| # If it doesn't take effect, try: | |
| killall SystemUIServer | |
| # Method 2 (GUI — easiest on Tahoe): press ⌘⇧5, click "Options", pick "Save to" | |
| # Change screenshot format (default is png; options: png, jpg, pdf, tiff, gif) | |
| defaults write com.apple.screencapture type jpg | |
| # Disable the floating thumbnail preview after taking a screenshot | |
| defaults write com.apple.screencapture show-thumbnail -bool false | |
| # Restore default screenshot behavior | |
| defaults delete com.apple.screencapture location | |
| defaults delete com.apple.screencapture type | |
| ``` | |
| ### Disk Management & Space Analysis | |
| ```bash | |
| # List all disks, partitions, and APFS volumes | |
| diskutil list | |
| # Show APFS container info (more relevant on modern macOS than fsck for most users) | |
| diskutil apfs list | |
| # File system check (HFS+ volumes only — most Tahoe installs use APFS) | |
| # Useful for external drives that are still HFS+ | |
| sudo /sbin/fsck_hfs -drfy /dev/disk2s3 | |
| # APFS: First Aid via Terminal (preferred on Tahoe) | |
| diskutil verifyVolume / | |
| # If errors found: | |
| # Boot into Recovery (hold Power on Apple Silicon) → Disk Utility → First Aid | |
| # Interactive disk space analysis (ncurses-based, very fast) | |
| brew install ncdu | |
| ncdu ~ # Scan home directory | |
| sudo ncdu / # Scan entire system (requires sudo for protected dirs) | |
| # macOS built-in alternative: get folder sizes | |
| du -sh ~/Documents/* # Summarize each item in Documents | |
| du -sh * | sort -hr # Sort current directory contents by size, largest first | |
| ``` | |
| ### System Information | |
| ```bash | |
| # Quick hardware overview | |
| system_profiler SPHardwareDataType | |
| # macOS version info | |
| sw_vers | |
| # Check if running under Rosetta 2 translation | |
| # ⚠️ Rosetta 2 is being phased out — Apple warns it will be largely | |
| # discontinued in macOS 28. Check your apps now! | |
| sysctl -n sysctl.proc_translated # Returns 1 if running under Rosetta | |
| # List all apps that require Rosetta (x86_64-only apps) | |
| system_profiler SPApplicationsDataType | grep -B 6 "Kind: Intel" | |
| ``` | |
| --- | |
| ## 3. Performance & Monitoring | |
| ```bash | |
| # ── Adjust process priority ── | |
| # renice values: -20 (highest priority) to 20 (lowest) | |
| # Negative values require sudo | |
| sudo renice -20 $(pgrep FaceTime) | |
| # ── Interactive process monitor (better than top) ── | |
| brew install htop | |
| htop | |
| # ── macOS virtual memory statistics ── | |
| # Shows pages free, active, inactive, wired, etc. | |
| vm_stat | |
| # ── Top 20 processes by memory usage ── | |
| # NOTE: macOS ps doesn't support --sort; use -m flag or pipe through sort | |
| ps aux | sort -nrk 4 | head -20 | |
| # ── Power and thermal monitoring (Apple Silicon) ── | |
| # Shows CPU/GPU power draw, thermal pressure, etc. — requires sudo | |
| sudo powermetrics -n 1 --samplers cpu_power,gpu_power | |
| # Continuous monitoring (updates every 2 seconds): | |
| sudo powermetrics --samplers cpu_power,gpu_power -i 2000 | |
| # ── macOS Activity Monitor from Terminal ── | |
| # Open Activity Monitor to a specific tab (CPU=0, Memory=1, Energy=2, Disk=3, Network=4) | |
| open -a "Activity Monitor" | |
| # ── Check thermal throttling status ── | |
| pmset -g thermlog | |
| ``` | |
| --- | |
| ## 4. File & Batch Operations | |
| ### Loops and Bulk File Operations | |
| ```bash | |
| # Loop through all items in current directory | |
| for dir in *; do echo "$dir"; done | |
| # Loop through specific file types | |
| for file in *.avi; do echo "$file"; done | |
| # Delete all .flac files recursively (dry-run first!) | |
| find . -name '*.flac' -type f # Preview what will be deleted | |
| find . -name '*.flac' -type f -delete # Actually delete | |
| # Delete PDFs smaller than 1KB (likely corrupt/empty) | |
| find . -type f -name "*.pdf" -size -1k -delete | |
| # Find large files (over 500MB) anywhere under home directory | |
| find ~ -type f -size +500M -exec ls -lh {} \; | |
| # Find files modified in the last 24 hours | |
| find . -type f -mtime -1 | |
| ``` | |
| ### Video Merging & Processing | |
| ```bash | |
| # ── Merge numbered .ts (transport stream) files ── | |
| cd ts_files_directory | |
| # Create a list of files 1.ts through 500.ts, then concatenate | |
| echo {1..500}.ts | tr " " "\n" > tslist | |
| while read line; do cat "$line" >> combined.ts; done < tslist | |
| rm tslist | |
| # ── Merge AVI files (requires mencoder from mplayer) ── | |
| brew install mplayer | |
| mencoder -oac copy -ovc copy 1.avi 2.avi 3.avi 4.avi 5.avi 6.avi -o final.avi | |
| # ── Merge and sort MP4 files with ffmpeg ── | |
| # Creates a file list, sorts naturally (1, 2, 10 not 1, 10, 2), then concatenates | |
| rm -f list.txt | |
| for f in *.mp4; do echo "file '$f'" >> list.txt; done | |
| sort -V list.txt > list-sort.txt | |
| ffmpeg -f concat -safe 0 -i list-sort.txt -c copy stitched-video.mp4 | |
| rm list.txt list-sort.txt | |
| # ── Batch compress MP4 files in parallel ── | |
| brew install parallel ffmpeg | |
| ls *.mp4 | parallel --jobs 4 'ffmpeg -i {} -c:v libx264 -preset fast -crf 28 {.}_compressed.mp4' | |
| # --jobs 4 = run 4 encodes simultaneously (adjust for your CPU core count) | |
| # -crf 28 = quality level (lower = better quality, bigger file; 18-28 is typical) | |
| # ── Convert video to H.265/HEVC for smaller files (Apple Silicon hardware encoder) ── | |
| ffmpeg -i input.mp4 -c:v hevc_videotoolbox -q:v 65 -c:a copy output_hevc.mp4 | |
| ``` | |
| --- | |
| ## 5. Development & DevOps | |
| ### SSH Key Management | |
| ```bash | |
| # ── Correct permissions (required — SSH refuses keys with wrong perms) ── | |
| chmod 700 ~/.ssh # Directory itself | |
| chmod 600 ~/.ssh/id_rsa # Private key: owner read/write ONLY | |
| chmod 644 ~/.ssh/id_rsa.pub # Public key: world-readable is fine | |
| chmod 600 ~/.ssh/config # SSH config file | |
| chmod 600 ~/.ssh/authorized_keys | |
| # ── Fix ownership ── | |
| # On macOS, your user owns these (not root). Replace 'user' with your username. | |
| chown $(whoami) ~/.ssh/id_rsa ~/.ssh/id_rsa.pub | |
| # ── Generate a modern SSH key (Ed25519 recommended over RSA) ── | |
| ssh-keygen -t ed25519 -C "your_email@example.com" | |
| # ── Add key to macOS Keychain so you don't re-enter passphrase ── | |
| ssh-add --apple-use-keychain ~/.ssh/id_ed25519 | |
| ``` | |
| ### Persistent SSH Tunnel | |
| ```bash | |
| # Forward remote Redis (port 6379) to localhost via a bastion/jump host | |
| # -N = no remote command, -T = no pseudo-terminal, -f = background | |
| ssh -NTf -L localhost:6379:remoteserver.com:6379 user@bastion.example.com | |
| # For persistent tunnels that auto-reconnect, use autossh: | |
| brew install autossh | |
| autossh -M 0 -NTf -L localhost:6379:remoteserver.com:6379 user@bastion.example.com | |
| # See ~/.ssh/config for more advanced setups (ProxyJump, IdentityFile, etc.) | |
| ``` | |
| ### Homebrew | |
| ```bash | |
| # ── Install Homebrew (Apple Silicon: installs to /opt/homebrew) ── | |
| /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)" | |
| # ── Uninstall Homebrew completely ── | |
| curl -O https://raw.githubusercontent.com/Homebrew/install/HEAD/uninstall.sh | |
| /bin/bash uninstall.sh | |
| # If you had an old Intel Homebrew at /usr/local: | |
| # /bin/bash uninstall.sh --path=/usr/local | |
| # ── Maintenance ── | |
| brew update # Update Homebrew itself + formulae list | |
| brew upgrade # Upgrade all installed packages | |
| brew cleanup # Remove old versions / cached downloads | |
| brew doctor # Diagnose common issues | |
| ``` | |
| ### Docker on Apple Silicon | |
| ```bash | |
| brew install docker | |
| # Pull architecture-specific images | |
| docker pull --platform linux/arm64 python:3.11 # Native ARM (faster) | |
| docker pull --platform linux/amd64 python:3.11 # Intel via emulation (slower) | |
| # Build multi-architecture images with buildx | |
| docker buildx create --use | |
| docker buildx build --platform linux/amd64,linux/arm64 -t myapp:latest --push . | |
| # ⚠️ Rosetta 2 is being phased out after macOS 27. | |
| # Ensure your Docker images and tools are arm64-native where possible. | |
| ``` | |
| ### MongoDB (via Homebrew) | |
| ```bash | |
| brew tap mongodb/brew | |
| brew install mongodb-community | |
| brew install mongodb-database-tools | |
| # Start MongoDB as a background service | |
| brew services start mongodb-community | |
| # Stop it | |
| brew services stop mongodb-community | |
| # Connect via shell | |
| mongosh | |
| ``` | |
| --- | |
| ## 6. Security, Network & Code Signing | |
| ### Remove App Quarantine Flag | |
| ```bash | |
| # macOS flags downloaded apps with a quarantine attribute. | |
| # If Gatekeeper blocks a trusted app, remove the flag: | |
| xattr -d com.apple.quarantine /Applications/Lepton.app | |
| # Recursively (for app bundles with nested files): | |
| xattr -r -d com.apple.quarantine "/Applications/Your App.app" | |
| # ⚠️ macOS Tahoe 26.4 introduced Terminal paste-protection warnings | |
| # for potentially harmful commands. This is informational only — | |
| # dismiss once and it won't appear again. | |
| ``` | |
| ### Code Signing & Notarization Verification | |
| ```bash | |
| # Ad-hoc sign an app (no Apple Developer identity needed — useful for | |
| # self-compiled apps or apps that lost their signature) | |
| codesign -f -s - --timestamp=none --all-architectures "/Applications/Your App.app" | |
| # Verify an app's code signature | |
| codesign -v --deep --strict /Applications/YourApp.app | |
| # Check Gatekeeper assessment (is the app notarized / allowed?) | |
| spctl -a -v /Applications/YourApp.app | |
| # Check notarization status specifically | |
| spctl --assess --verbose=4 --type execute /Applications/YourApp.app | |
| ``` | |
| ### Network Diagnostics | |
| ```bash | |
| # ── DNS lookup ── | |
| # dig is now included in macOS, but you can also install the latest via brew | |
| dig example.com | |
| dig +short example.com | |
| nslookup example.com | |
| # ── HTTP proxy / traffic inspection ── | |
| brew install mitmproxy | |
| mitmproxy -p 8080 | |
| # In another terminal, route traffic through the proxy: | |
| curl -x 127.0.0.1:8080 https://api.example.com/endpoint | |
| # ── Inspect TLS/SSL certificates ── | |
| openssl s_client -connect api.example.com:443 -showcerts | |
| # ── Network interface statistics ── | |
| netstat -in | |
| # Or the modern replacement: | |
| networksetup -listallhardwareports | |
| ifconfig | grep "inet " | |
| # ── Monitor per-process bandwidth usage ── | |
| brew install nethogs | |
| sudo nethogs | |
| # ── Test network speed from Terminal ── | |
| networkQuality # Built-in macOS tool (since Monterey) | |
| # or | |
| brew install speedtest-cli | |
| speedtest-cli | |
| # ── Flush DNS cache ── | |
| sudo dscacheutil -flushcache; sudo killall -HUP mDNSResponder | |
| ``` | |
| --- | |
| ## 7. Reference & Quick Tools | |
| ### iCloud Drive Path | |
| ```bash | |
| # Your iCloud Drive files live here: | |
| ls "$HOME/Library/Mobile Documents/com~apple~CloudDocs" | |
| # All iCloud-synced app containers: | |
| ls "$HOME/Library/Mobile Documents" | |
| ``` | |
| ### Backup Dotfiles with Git | |
| ```bash | |
| mkdir -p ~/dotfiles | |
| cp ~/.ssh/config ~/.gitconfig ~/.zshrc ~/.zprofile ~/dotfiles/ | |
| # Symlink so edits in ~/dotfiles are used system-wide | |
| ln -sf ~/dotfiles/.zshrc ~/.zshrc | |
| ln -sf ~/dotfiles/.gitconfig ~/.gitconfig | |
| cd ~/dotfiles | |
| git init | |
| git add . | |
| git commit -m "Initial config backup" | |
| git remote add origin git@github.com:yourusername/dotfiles.git | |
| git push -u origin main | |
| # After cloning on a new machine, re-create symlinks: | |
| # ln -sf ~/dotfiles/.zshrc ~/.zshrc | |
| # etc. | |
| ``` | |
| ### Split a Large Folder into Chunks of 1000 Files | |
| ```bash | |
| # Distributes files into subdirectories: dir_001, dir_002, etc. | |
| i=0 | |
| for f in *; do | |
| d=dir_$(printf %03d $((i/1000+1))) | |
| mkdir -p "$d" | |
| mv "$f" "$d" | |
| ((i++)) | |
| done | |
| ``` | |
| ### Remove Node.js Completely | |
| ```bash | |
| # ── If installed via Homebrew (recommended approach): ── | |
| brew uninstall node | |
| brew cleanup | |
| # ── If installed via nvm (Node Version Manager): ── | |
| nvm deactivate | |
| nvm uninstall <version> | |
| rm -rf ~/.nvm | |
| # ── Manual nuclear cleanup (if installed via pkg/binary): ── | |
| sudo rm -rf /usr/local/bin/node /usr/local/bin/npm /usr/local/bin/npx | |
| sudo rm -rf /usr/local/lib/node_modules | |
| sudo rm -rf /usr/local/include/node | |
| sudo rm -rf /usr/local/share/man/man1/node.1 | |
| sudo rm -rf /usr/local/lib/dtrace/node.d | |
| sudo rm -rf /opt/local/bin/node /opt/local/include/node /opt/local/lib/node_modules | |
| rm -rf ~/.npm ~/.node-gyp ~/.node_repl_history | |
| ``` | |
| ### System Extension Cleanup | |
| ```bash | |
| # ⚠️ Kernel extensions (kexts) are fully deprecated on macOS Tahoe. | |
| # Apple recommends System Extensions and DriverKit instead. | |
| # Most kext commands below only apply to legacy third-party kexts. | |
| # List loaded kexts (if any remain) | |
| kextstat | grep -v com.apple | |
| # Remove a third-party kext | |
| sudo rm -rf /Library/Extensions/<kextname.kext> | |
| # Rebuild kext cache (legacy — may not be needed on Tahoe) | |
| sudo kextcache -i / | |
| sudo kextcache --clear-staging | |
| # List modern System Extensions (the replacement for kexts) | |
| systemextensionsctl list | |
| # After removing kexts, reboot for changes to take effect | |
| sudo reboot | |
| ``` | |
| --- | |
| ## 8. Apple Silicon Specific | |
| ```bash | |
| # ── Install Rosetta 2 (for running Intel x86_64 apps) ── | |
| # ⚠️ Rosetta 2 will be largely discontinued in macOS 28. | |
| # Migrate to arm64-native tools as soon as possible. | |
| softwareupdate --install-rosetta --agree-to-license | |
| # ── Check if a binary is Intel-only, ARM, or Universal ── | |
| file /usr/local/bin/somebinary | |
| lipo -archs /Applications/SomeApp.app/Contents/MacOS/SomeApp | |
| # "x86_64" = Intel only (needs Rosetta) | |
| # "arm64" = Apple Silicon native | |
| # "x86_64 arm64" = Universal Binary (runs natively on both) | |
| # ── CMake fix: force x86_64 build for an Intel-only library ── | |
| # Add to CMakeLists.txt: | |
| # set(CMAKE_OSX_ARCHITECTURES "x86_64" CACHE INTERNAL "" FORCE) | |
| # ── Run a specific binary under Rosetta explicitly ── | |
| arch -x86_64 /usr/local/bin/somebinary | |
| # ── Run an entire Terminal session under Rosetta ── | |
| arch -x86_64 /bin/zsh | |
| ``` | |
| --- | |
| ## 9. Scripting & Automation | |
| ### AppleScript Examples | |
| ```bash | |
| # ── Copy all tabs from Brave Browser to Safari ── | |
| osascript -e ' | |
| tell application "Brave Browser" | |
| set tab_list to every tab in the front window | |
| repeat with the_tab in tab_list | |
| set the_url to the URL of the_tab | |
| tell application "Safari" to open location the_url | |
| end repeat | |
| end tell' | |
| # ── Send an iMessage from Terminal ── | |
| osascript -e 'tell application "Messages" to send "Hello World!" to buddy "+11234567890"' | |
| # ── Get the frontmost app name ── | |
| osascript -e 'tell application "System Events" to get name of first process whose frontmost is true' | |
| # ── Toggle Dark Mode ── | |
| osascript -e 'tell app "System Events" to tell appearance preferences to set dark mode to not dark mode' | |
| # ── Set volume (0–100) ── | |
| osascript -e 'set volume output volume 50' | |
| ``` | |
| ### Open Multiple Instances of an App | |
| ```bash | |
| # Useful for apps like WeChat that normally only allow one instance | |
| nohup /Applications/WeChat.app/Contents/MacOS/WeChat > /dev/null 2>&1 & | |
| # For the enterprise version (企业微信) | |
| nohup /Applications/企业微信.app/Contents/MacOS/企业微信 > /dev/null 2>&1 & | |
| # Generic: open any app as a new instance | |
| open -n -a "AppName" | |
| ``` | |
| ### Generate Random Passwords | |
| ```bash | |
| # Generate 5 random 20-character passwords with special characters | |
| for i in $(seq 1 5); do | |
| LC_ALL=C tr -dc 'A-Za-z0-9!#$%&()*+,-./:;<=>?@[\]^_{|}~' < /dev/urandom | head -c 20 | |
| echo | |
| done | |
| # Simpler alternative using openssl: | |
| openssl rand -base64 24 | head -c 20; echo | |
| # Generate a macOS-Keychain-compatible passphrase: | |
| LC_ALL=C tr -dc 'A-Za-z0-9' < /dev/urandom | fold -w 32 | head -5 | |
| ``` | |
| ### Hide a User Account from the Login Screen | |
| ```bash | |
| sudo dscl . create /Users/<hiddenuser> IsHidden 1 | |
| # To unhide: | |
| sudo dscl . create /Users/<hiddenuser> IsHidden 0 | |
| ``` | |
| --- | |
| ## 10. Data Processing & Regex | |
| ### Useful Regex Patterns | |
| ``` | |
| \<[^\>]*\> # Strip HTML tags | |
| (https?|ftp|ssh)://[^\s/$.?#].[^\s]* # URL | |
| [a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,} # Email address | |
| \d+\.?\d* # Number (int or float) | |
| [a-fA-F0-9]{32}|[a-fA-F0-9]{64} # MD5 or SHA256 hash | |
| \b[13][a-km-zA-HJ-NP-Z1-9]{25,34}\b # Bitcoin address | |
| "([^"\\]|\\.)*" # JSON string value | |
| 0x[a-fA-F0-9]{40} # Ethereum address | |
| \b\d{1,3}(\.\d{1,3}){3}\b # IPv4 address | |
| ``` | |
| ### Python One-Liners | |
| ```bash | |
| # Pretty-print JSON from an API and grep for a field | |
| curl -s https://api.example.com/data | python3 -m json.tool | grep "price" | |
| # Extract and compute stats from a CSV column | |
| python3 -c " | |
| import csv | |
| data = [float(row['price']) for row in csv.DictReader(open('prices.csv'))] | |
| print(f'Count: {len(data)}, Mean: {sum(data)/len(data):.2f}, Max: {max(data)}, Min: {min(data)}') | |
| " | |
| # Extract all URLs from a text file | |
| cat document.txt | python3 -c "import sys, re; print('\n'.join(re.findall(r'https?://\S+', sys.stdin.read())))" | |
| # Batch rename .txt files to .md | |
| python3 -c "import os; [os.rename(f, f.replace('.txt', '.md')) for f in os.listdir('.') if f.endswith('.txt')]" | |
| # Count total lines of code in Python files | |
| find . -name "*.py" -type f -exec wc -l {} + | tail -1 | |
| ``` | |
| ### Batch Extract Text from EPUB Files | |
| ```bash | |
| for epub in *.epub; do | |
| echo "Processing $epub..." | |
| unzip -q -c "$epub" | strings | grep -v "^$" > "${epub%.epub}.txt" 2>/dev/null && \ | |
| echo "✔ $epub processed" || echo "✗ Failed: $epub" | |
| done | |
| ``` | |
| --- | |
| ## 11. Miscellaneous | |
| ### Install Common CLI Tools (one-liner) | |
| ```bash | |
| brew install htop ncdu parallel mitmproxy ffmpeg fdupes fswatch nethogs autossh | |
| ``` | |
| ### Find and Remove Duplicate Files | |
| ```bash | |
| brew install fdupes | |
| # List duplicate files recursively | |
| fdupes -r . | |
| # Automatically delete duplicates (keeps one copy, no prompts) | |
| # ⚠️ Use with caution — preview with fdupes -r . first! | |
| fdupes -rdN . | |
| ``` | |
| ### Batch Download URLs | |
| ```bash | |
| # Download files listed in urls.txt (one URL per line) | |
| xargs -n 1 curl -O -L < urls.txt | |
| # Parallel downloads for speed (4 at a time): | |
| cat urls.txt | parallel --jobs 4 'curl -O -L {}' | |
| # Alternative: use wget for retries and recursive downloads | |
| brew install wget | |
| wget -i urls.txt | |
| ``` | |
| ### Preserve Folder Structure When Copying Specific File Types | |
| ```bash | |
| # Copy only .pdf and .jpg files, maintaining directory structure | |
| rsync -av --include '*/' --include '*.pdf' --include '*.jpg' --exclude '*' source_folder/ destination_folder/ | |
| # Dry run first (shows what would be copied without copying): | |
| rsync -avn --include '*/' --include '*.pdf' --include '*.jpg' --exclude '*' source_folder/ destination_folder/ | |
| ``` | |
| ### Useful macOS `defaults` Tweaks | |
| ```bash | |
| # Show hidden files in Finder | |
| defaults write com.apple.finder AppleShowAllFiles -bool true; killall Finder | |
| # Show file extensions in Finder | |
| defaults write NSGlobalDomain AppleShowAllExtensions -bool true; killall Finder | |
| # Disable .DS_Store files on network and USB volumes | |
| defaults write com.apple.desktopservices DSDontWriteNetworkStores -bool true | |
| defaults write com.apple.desktopservices DSDontWriteUSBStores -bool true | |
| # Speed up Mission Control animation | |
| defaults write com.apple.dock expose-animation-duration -float 0.1; killall Dock | |
| # Expand save panel by default | |
| defaults write NSGlobalDomain NSNavPanelExpandedStateForSaveMode -bool true | |
| ``` | |
| --- | |
| ## Summary of Key Changes for macOS Tahoe (26) | |
| | Topic | What Changed | | |
| |---|---| | |
| | **launchctl** | `load`/`unload` are legacy. Use `bootstrap`/`bootout` with domain targets instead. | | |
| | **Rosetta 2** | Still works on Tahoe, but 26.4 shows warnings. Will be largely removed in macOS 28. Check your apps with `system_profiler SPApplicationsDataType`. | | |
| | **Kernel Extensions** | Fully deprecated. Use System Extensions / DriverKit. `kextstat` may show nothing on a clean Tahoe install. | | |
| | **Shortcuts Automations** | Brand-new on macOS. Trigger workflows on file changes, time, display connect/disconnect, and more — no scripting needed. | | |
| | **Terminal Security** | macOS 26.4 warns when pasting potentially harmful commands. Informational only; dismiss once. | | |
| | **Screenshots** | `killall SystemUIServer` is mostly unnecessary now. Use ⌘⇧5 → Options, or `defaults write` takes effect immediately. | | |
| | **Cron** | Still works but has been "deprecated" by Apple for over a decade. Consider migrating to launchd or Shortcuts Automations. | | |
| ``` | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment