Awesome MacOs Command Line – Massive Collection Of Shell Commands – You Ever Wondered To Get!
A curated list of shell commands and tools specific to OS X.
“You don’t have to know everything. You simply need to know where to find it when necessary.” (John Brunner)
If you want to contribute, you are highly encouraged to do so. Please read the contribution guidelines.
For more terminal shell goodness, please also see this list’s sister list Awesome Command Line Apps.
Caffeinating
When you find something helpful in here, you could buy me a coffee. I spend a lot of time and effort on curating this list. Keeping me properly caffeinated accelerates things. And it would really make my day. Kindness of strangers and all that. If you can’t or won’t, no hard feelings. It’s available completely free for a reason. Still, it would be awesome.
Foreword
There’s really only one thing I’d like to note here: man pages. Man pages. Man pages. Okay, three things. But this one thing seemed so important, I had to mention it multiple times. If you’re not doing it already, you should get into the habit of consulting man pages before searching anywhere else. Unix-style man pages are an excellent source of documentation. There’s even a man page for the man
command itself:
man man
It also explains what the numbers in the man pages refer to — like man(1)
.
Contents
- Appearance
- Applications
- Backup
- Developer
- Dock
- Documents
- Files, Disks and Volumes
- Finder
- Fonts
- Functions
- Hardware
- Input Devices
- Launchpad
- Media
- Networking
- Package Managers
- Printing
- Security
- Search
- System
- AirDrop
- AppleScript
- Basics
- Clipboard
- Date and Time
- FileVault
- Information/Reports
- Installation
- Kernel Extensions
- LaunchAgents
- LaunchServices
- Login Window
- Memory Management
- Notification Center
- QuickLook
- Remote Management
- Root User
- Safe Mode Boot
- Save Dialogs
- Screenshots
- Sidecar
- Software Installation
- Software Update
- Software Version
- Spotlight
- System Integrity Protection
- Terminal
- Glossary
Appearance
Subpixel Anti-Aliasing (Font Smoothing)
Setting present since macOS 10.14 (Mojave).
# Enable defaults write -g CGFontRenderingFontSmoothingDisabled -bool false # Disable (Default) defaults write -g CGFontRenderingFontSmoothingDisabled -bool true # Per Application defaults write com.apple.textedit CGFontRenderingFontSmoothingDisabled -bool false # Revert for Application defaults delete com.apple.textedit CGFontRenderingFontSmoothingDisabled
Transparency
Transparency in Menu and Windows
# Reduce Transparency defaults write com.apple.universalaccess reduceTransparency -bool true # Restore Default Transparency defaults write com.apple.universalaccess reduceTransparency -bool false
Wallpaper
Set Wallpaper
# Up to OS X 10.8 (Mountain Lion) osascript -e 'tell application "Finder" to set desktop picture to POSIX file "/path/to/picture.jpg"' # Since OS X 10.9 (Mavericks) sqlite3 ~/Library/Application\ Support/Dock/desktoppicture.db "update data set value = '/path/to/picture.jpg'" && killall Dock
Applications
App Store
List All Apps Downloaded from App Store
# Via find find /Applications -path '*Contents/_MASReceipt/receipt' -maxdepth 4 -print |\sed 's#.app/Contents/_MASReceipt/receipt#.app#g; s#/Applications/##' # Via Spotlight mdfind kMDItemAppStoreHasReceipt=1
Show Debug Menu
Works up to OS X 10.10 (Yosemite).
# Enable defaults write com.apple.appstore ShowDebugMenu -bool true # Disable (Default) defaults write com.apple.appstore ShowDebugMenu -bool false
Apple Remote Desktop
Kickstart Manual Pages
sudo /System/Library/CoreServices/RemoteManagement/ARDAgent.app/Contents/Resources/kickstart -help
Activate And Deactivate the ARD Agent and Helper
# Activate And Restart the ARD Agent and Helper sudo /System/Library/CoreServices/RemoteManagement/ARDAgent.app/Contents/Resources/kickstart -activate -restart -agent -console # Deactivate and Stop the Remote Management Service sudo /System/Library/CoreServices/RemoteManagement/ARDAgent.app/Contents/Resources/kickstart -deactivate -stop
Remote Desktop Sharing
# Allow Access for All Users and Give All Users Full Access sudo /System/Library/CoreServices/RemoteManagement/ARDAgent.app/Contents/Resources/kickstart -configure -allowAccessFor -allUsers -privs -all # Disable ARD Agent and Remove Access Privileges for All Users (Default) sudo /System/Library/CoreServices/RemoteManagement/ARDAgent.app/Contents/Resources/kickstart -deactivate -configure -access -off
Remove Apple Remote Desktop Settings
sudo rm -rf /var/db/RemoteManagement ; \ sudo defaults delete /Library/Preferences/com.apple.RemoteDesktop.plist ; \ defaults delete ~/Library/Preferences/com.apple.RemoteDesktop.plist ; \ sudo rm -r /Library/Application\ Support/Apple/Remote\ Desktop/ ; \ rm -r ~/Library/Application\ Support/Remote\ Desktop/ ; \ rm -r ~/Library/Containers/com.apple.RemoteDesktop
Contacts
Debug Mode
# Enable defaults write com.apple.addressbook ABShowDebugMenu -bool true # Disable (Default) defaults write com.apple.addressbook ABShowDebugMenu -bool false
Uninstall Google Update
~/Library/Google/GoogleSoftwareUpdate/GoogleSoftwareUpdate.bundle/Contents/Resources/ksinstall --nuke
iTunes
Keyboard Media Keys
Works up to OS X 10.10 (Yosemite). System Integrity Protection was introduced in OS X 10.11 (El Capitan) which prevents system Launch Agents from being unloaded.
# Stop Responding to Key Presses launchctl unload -w /System/Library/LaunchAgents/com.apple.rcd.plist # Respond to Key Presses (Default) launchctl load -w /System/Library/LaunchAgents/com.apple.rcd.plist
From OS X 10.11 (El Capitan) on, you can either disable SIP or resort to a kind of hack, which will make iTunes inaccessible to any user, effectively preventing it from starting itself or its helpers. Be aware that for all intents and purposes this will trash your iTunes installation and may conflict with OS updates down the road.
sudo chmod 0000 /Applications/iTunes.app
Show Attachments as Icons
defaults write com.apple.mail DisableInlineAttachmentViewing -bool yes
Vacuum Mail Index
The AppleScript code below will quit Mail, vacuum the SQLite index, then re-open Mail. On a large email database that hasn’t been optimized for a while, this can provide significant improvements in responsiveness and speed.
(* Speed up Mail.app by vacuuming the Envelope Index Code from: http://web.archive.org/web/20071008123746/http://www.hawkwings.net/2007/03/03/scripts-to-automate-the-mailapp-envelope-speed-trick/ Originally by "pmbuko" with modifications by Romulo Updated by Brett Terpstra 2012 Updated by Mathias Törnblom 2015 to support V3 in El Capitan and still keep backwards compatibility Updated by Andrei Miclaus 2017 to support V4 in Sierra *) tell application "Mail" to quit set os_version to do shell script "sw_vers -productVersion" set mail_version to "V2" considering numeric strings if "10.10" <= os_version then set mail_version to "V3" if "10.12" <= os_version then set mail_version to "V4" if "10.13" <= os_version then set mail_version to "V5" if "10.14" <= os_version then set mail_version to "V6" end considering set sizeBefore to do shell script "ls -lnah ~/Library/Mail/" & mail_version & "/MailData | grep -E 'Envelope Index$' | awk {'print $5'}" do shell script "/usr/bin/sqlite3 ~/Library/Mail/" & mail_version & "/MailData/Envelope\\ Index vacuum" set sizeAfter to do shell script "ls -lnah ~/Library/Mail/" & mail_version & "/MailData | grep -E 'Envelope Index$' | awk {'print $5'}" display dialog ("Mail index before: " & sizeBefore & return & "Mail index after: " & sizeAfter & return & return & "Enjoy the new speed!") tell application "Mail" to activate
Safari
Change Default Fonts
defaults write com.apple.Safari com.apple.Safari.ContentPageGroupIdentifier.WebKit2StandardFontFamily Georgia defaults write com.apple.Safari com.apple.Safari.ContentPageGroupIdentifier.WebKit2DefaultFontSize 16 defaults write com.apple.Safari com.apple.Safari.ContentPageGroupIdentifier.WebKit2FixedFontFamily Menlo defaults write com.apple.Safari com.apple.Safari.ContentPageGroupIdentifier.WebKit2DefaultFixedFontSize 14
Develop Menu and Web Inspector
# Enable defaults write com.apple.Safari IncludeInternalDebugMenu -bool true && \ defaults write com.apple.Safari IncludeDevelopMenu -bool true && \ defaults write com.apple.Safari WebKitDeveloperExtrasEnabledPreferenceKey -bool true && \ defaults write com.apple.Safari com.apple.Safari.ContentPageGroupIdentifier.WebKit2DeveloperExtrasEnabled -bool true && \ defaults write -g WebKitDeveloperExtras -bool true # Disable (Default) defaults delete com.apple.Safari IncludeInternalDebugMenu && \ defaults delete com.apple.Safari IncludeDevelopMenu && \ defaults delete com.apple.Safari WebKitDeveloperExtrasEnabledPreferenceKey && \ defaults delete com.apple.Safari com.apple.Safari.ContentPageGroupIdentifier.WebKit2DeveloperExtrasEnabled && \ defaults delete -g WebKitDeveloperExtras
Get Current Page Data
Other options: get source
, get text
.
osascript -e 'tell application "Safari" to get URL of current tab of front window'
Use Backspace/Delete to Go Back a Page
# Enable defaults write com.apple.Safari com.apple.Safari.ContentPageGroupIdentifier.WebKit2BackspaceKeyNavigationEnabled -bool YES # Disable (Default) defaults write com.apple.Safari com.apple.Safari.ContentPageGroupIdentifier.WebKit2BackspaceKeyNavigationEnabled -bool NO
Sketch
Export Compact SVGs
defaults write com.bohemiancoding.sketch3 exportCompactSVG -bool yes
Skim
Turn Off Auto Reload Dialog
Removes the dialog and defaults to auto reload.
defaults write -app Skim SKAutoReloadFileUpdate -boolean true
Terminal
Focus Follows Mouse
# Enable defaults write com.apple.Terminal FocusFollowsMouse -string YES # Disable (Default) defaults write com.apple.Terminal FocusFollowsMouse -string NO
TextEdit
Use Plain Text Mode as Default
defaults write com.apple.TextEdit RichText -int 0
Visual Studio Code
VSCodeVim Key Repeat
# Enable defaults write com.microsoft.VSCode ApplePressAndHoldEnabled -bool false # Disable (Default) defaults delete com.microsoft.VSCode ApplePressAndHoldEnabled
Subpixel Anti-Aliasing
Setting present since macOS 10.14 (Mojave). See also system-wide setting: Subpixel Anti-Aliasing
# Enable defaults write com.microsoft.VSCode CGFontRenderingFontSmoothingDisabled -bool false && \ defaults write com.microsoft.VSCode.helper CGFontRenderingFontSmoothingDisabled -bool false && \ defaults write com.microsoft.VSCode.helper.EH CGFontRenderingFontSmoothingDisabled -bool false && \ defaults write com.microsoft.VSCode.helper.NP CGFontRenderingFontSmoothingDisabled -bool false # Disable (Default) defaults delete com.microsoft.VSCode CGFontRenderingFontSmoothingDisabled && \ defaults delete com.microsoft.VSCode.helper CGFontRenderingFontSmoothingDisabled && \ defaults delete com.microsoft.VSCode.helper.EH CGFontRenderingFontSmoothingDisabled && \ defaults delete com.microsoft.VSCode.helper.NP CGFontRenderingFontSmoothingDisabled
Backup
Time Machine
Change Backup Interval
This changes the interval to 30 minutes. The integer value is the time in seconds.
sudo defaults write /System/Library/LaunchDaemons/com.apple.backupd-auto StartInterval -int 1800
Local Backups
Whether Time Machine performs local backups while the Time Machine backup volume is not available.
# Status defaults read /Library/Preferences/com.apple.TimeMachine MobileBackups # Enable (Default) sudo tmutil enablelocal # Disable sudo tmutil disablelocal
Since macOS 10.13 (High Sierra), you cannot disable local snapshots. Time Machine now always creates a local APFS snapshot and uses that snapshot as the data source to create a regular backup, rather than using the live disk as the source, as is the case with HFS formatted disks.
Prevent Time Machine from Prompting to Use New Hard Drives as Backup Volume
sudo defaults write /Library/Preferences/com.apple.TimeMachine DoNotOfferNewDisksForBackup -bool true
Show Time Machine Logs
This little script will output the last 12 hours of Time Machine activity followed by live activity.
#!/bin/sh filter='processImagePath contains "backupd" and subsystem beginswith "com.apple.TimeMachine"' # show the last 12 hours start="$(date -j -v-12H +'%Y-%m-%d %H:%M:%S')" echo "" echo "[History (from $start)]" echo "" log show --style syslog --info --start "$start" --predicate "$filter" echo "" echo "[Following]" echo "" log stream --style syslog --info --predicate "$filter"
Toggle Backup While on Battery
# Status sudo defaults read /Library/Preferences/com.apple.TimeMachine RequiresACPower # Enable (Default) sudo defaults write /Library/Preferences/com.apple.TimeMachine RequiresACPower -bool true # Disable sudo defaults write /Library/Preferences/com.apple.TimeMachine RequiresACPower -bool false
Verify Backup
Beginning in OS X 10.11, Time Machine records checksums of files copied into snapshots. Checksums are not retroactively computed for files that were copied by earlier releases of OS X.
sudo tmutil verifychecksums /path/to/backup
Developer
Vim
Compile Sane Vim
Compiling MacVim via Homebrew with all bells and whistles, including overriding system Vim.
brew install macvim --HEAD
Neovim
Install the modern Vim drop-in alternative via Homebrew.
brew install neovim
Xcode
Install Command Line Tools without Xcode
xcode-select --install
Remove All Unavailable Simulators
xcrun simctl delete unavailable
Dock
Add a Stack with Recent Applications
Obsolete since macOS 10.14 (Mojave). See Show Recent Apps.
defaults write com.apple.dock persistent-others -array-add '{ "tile-data" = { "list-type" = 1; }; "tile-type" = "recents-tile"; }' && \ killall Dock
Add a Nameless Stack Folder and Small Spacer
defaults write com.apple.dock persistent-others -array-add '{ "tile-data" = {}; "tile-type"="small-spacer-tile"; }' && \ killall Dock
Add a Space
defaults write com.apple.dock persistent-apps -array-add '{"tile-type"="spacer-tile";}' && \ killall Dock
Add a Small Space
defaults write com.apple.dock persistent-apps -array-add '{"tile-type"="small-spacer-tile";}' && \ killall Dock
Auto Rearrange Spaces Based on Most Recent Use
# Enable (Default) defaults write com.apple.dock mru-spaces -bool true && \ killall Dock # Disable defaults write com.apple.dock mru-spaces -bool false && \ killall Dock
Automatically Hide
# Enable defaults write com.apple.dock autohide -bool true && \ killall Dock # Disable (Default) defaults write com.apple.dock autohide -bool false && \ killall Dock
Icon Bounce
Global setting whether Dock icons should bounce when the respective application demands your attention.
# Enable (Default) defaults write com.apple.dock no-bouncing -bool true && \ killall Dock # Disable defaults write com.apple.dock no-bouncing -bool false && \ killall Dock
Lock the Dock Size
# Enable defaults write com.apple.Dock size-immutable -bool yes && \ killall Dock # Disable (Default) defaults write com.apple.Dock size-immutable -bool no && \ killall Dock
Reset Dock
defaults delete com.apple.dock && \ killall Dock
Resize
Fully resize your Dock’s body. To resize change the 0
value as an integer.
defaults write com.apple.dock tilesize -int 0 && \ killall Dock
Scroll Gestures
Use your touchpad or mouse scroll wheel to interact with Dock items. Allows you to use an upward scrolling gesture to open stacks. Using the same gesture on applications that are running invokes Exposé/Mission Control.
# Enable defaults write com.apple.dock scroll-to-open -bool true && \ killall Dock # Disable (Default) defaults write com.apple.dock scroll-to-open -bool false && \ killall Dock
Set Auto Show/Hide Delay
The float number defines the show/hide delay in ms.
defaults write com.apple.dock autohide-time-modifier -float 0.4 && \ defaults write com.apple.dock autohide-delay -float 0 && \ killall Dock
Show Hidden App Icons
# Enable defaults write com.apple.dock showhidden -bool true && \ killall Dock # Disable (Default) defaults write com.apple.dock showhidden -bool false && \ killall Dock
Show Only Active Applications
# Enable defaults write com.apple.dock static-only -bool true && \ killall Dock # Disable (Default) defaults write com.apple.dock static-only -bool false && \ killall Dock
Show Recent Apps
Setting present since macOS 10.14 (Mojave).
# Disable defaults write com.apple.dock show-recents -bool false && \ killall Dock # Enable (Default) defaults write com.apple.dock show-recents -bool true && \ killall Dock
Single App Mode
When clicking an application icon in the Dock, the respective windows will come to the front, but all other application windows will be hidden.
# Enable defaults write com.apple.dock single-app -bool true && \ killall Dock # Disable (Default) defaults write com.apple.dock single-app -bool false && \ killall Dock
Documents
Convert File to HTML
Supported formats are plain text, rich text (rtf) and Microsoft Word (doc/docx).
textutil -convert html file.ext