assets | ||
contributing.md | ||
README.md |
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.
Table of Contents
- Appearance
- Applications
- Backup
- Developer
- Disks and Volumes
- Documents
- Finder
- Fonts
- Hardware
- Input Devices
- Media
- Networking
- Package Managers
- Printing
- Security
- System
Appearance
Transparency
Disable Transparency in Menu and Windows
defaults write com.apple.universalaccess reduceTransparency -bool true
Enable Transparency in Menu and Windows
defaults write com.apple.universalaccess reduceTransparency -bool false
Wallpaper
Set Wallpaper
osascript -e 'tell application "Finder" to set desktop picture to POSIX file "/path/to/picture.jpg"'
Applications
App Store
List All Apps Downloaded from App Store
find /Applications -path '*Contents/_MASReceipt/receipt' -maxdepth 4 -print |\sed 's#.app/Contents/_MASReceipt/receipt#.app#g; s#/Applications/##'
Apple Remote Desktop
Remove Apple Remote Desktop Settings
sudo rm -rf /var/db/RemoteManagement
sudo rm /Library/Preferences/com.apple.RemoteDesktop.plist
rm ~/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
Sketch
Export Compact SVGs
defaults write com.bohemiancoding.sketch3 exportCompactSVG -bool yes
Developer
Xcode
Install Command Line Tools Without Xcode
xcode-select --install
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/Launch Daemons/com.apple.backupd-auto StartInterval -int 1800
Disable Local Time Machine Backups
hash tmutil &> /dev/null && sudo tmutil disablelocal
Prevent Time Machine From Prompting to Use New Hard Drives as Backup Volume
defaults write com.apple.TimeMachine DoNotOfferNewDisksForBackup -bool true
Disks and Volumes
Disable Sudden Motion Sensor
Leaving this turned on is useless when you're using SSDs.
sudo pmset -a sms 0
Eject All Mountable Volumes
The only reliable way to do this is by sending an AppleScript command to Finder.
osascript -e 'tell application "Finder" to eject (every disk whose ejectable is true)'
Make Volume OS X Bootable
bless --folder "/path/to/mounted/volume/System/Library/CoreServices" --bootinfo --bootefi
Mount Disk Image
hdiutil attach /path/to/diskimage.dmg
Unmount Disk Image
hdiutil detach /dev/disk2s1
Repair File Permissions
You don't have to use the Disk Utility GUI for this.
sudo diskutil repairPermissions /
Set Boot Volume
bless --mount "/path/to/mounted/volume" --setBoot
Show All Attached Disks and Partitions
diskutil list
Documents
Convert File to HTML
Supported formats are plain text, rich text (rtf) and Microsoft Word (doc/docx).
textutil -convert html file.ext
Finder
Hide folder in Finder
chflags hidden /path/to/folder/
Show All Hidden Files
defaults write com.apple.finder AppleShowAllFiles true
Restore Default File Visibility
defaults write com.apple.finder AppleShowAllFiles false
Unhide User Library folder
chflags nohidden ~/Library
Fonts
Clear Font Cache for Current User
To clear font caches for all users, put sudo
in front of this command.
atsutil databases -removeUser && atsutil server -shutdown && atsutil server -ping
Hardware
Disable sudden motion sensor (useless for SSDs)
sudo pmset -a sms 0
Hardware Information
List All Hardware Ports
networksetup -listallhardwareports
Show Current Screen Resolution
system_profiler SPDisplaysDataType | grep Resolution
Power Management
Prevent System Sleep
Prevent sleep for 1 hour:
caffeinate -u -t 3600
Show All Power Management Settings
sudo pmset -g
Put Display to Sleep After 15 Minutes of Inactivity
sudo pmset displaysleep 15
Put Computer to Sleep After 30 Minutes of Inactivity
sudo pmset sleep 30
Check System Sleep Idle Time
sudo systemsetup -getcomputersleep
Set System Sleep Idle Time to 60 Minutes
sudo systemsetup -setcomputersleep 60
Turn Off System Sleep Completely
sudo systemsetup -setcomputersleep Never
Input Devices
Keyboard
Disable Auto-Correct
defaults write -g NSAutomaticSpellingCorrectionEnabled -bool false
Enable Auto-Correct
defaults write -g NSAutomaticSpellingCorrectionEnabled -bool true
Show Auto-Correct Setting
defaults read -g NSAutomaticSpellingCorrectionEnabled
Media
Audio
Convert Audio File to iPhone Ringtone
afconvert input.mp3 ringtone.m4r -f m4af
Play Audio File
You can play all audio formats that are natively supported by QuickTime.
afplay -q 1 filename.mp3
Networking
Bonjour
Disable Bonjour
defaults write /System/Library/LaunchDaemons/com.apple.mDNSResponder ProgramArguments -array "/usr/sbin/mDNSResponder" "-launchd"
Enable Bonjour
defaults write /System/Library/LaunchDaemons/com.apple.mDNSResponder ProgramArguments -array-add "-NoMulticastAdvertisements"
DHCP
Renew DHCP Lease
sudo ipconfig set en0 DHCP
Show DHCP Info
ipconfig getpacket en0
DNS
Clear DNS Cache
sudo dscachutil -flushcache && sudo killall -HUP mDNSResponder
Hostname
Set Hostname
You need to run all of the commands since the hostname needs to be changed in three places.
sudo scutil --set ComputerName "newhostname"
sudo scutil --set LocalHostName "newhostname"
sudo scutil --set HostName "newhostname"
Networking Tools
Ping a Host to See Whether It’s Available
ping -o github.com
Troubleshoot Routing Problems
traceroute github.com
Wi-Fi
Scan Available Access Points
Create a symbolic link to the airport command for easy access:
sudo ln -s /System/Library/PrivateFrameworks/Apple80211.framework/Versions/Current/Resources/airport /usr/local/bin/airport
Run a wireless scan:
airport -s
Show Wi-Fi Connection History
defaults read /Library/Preferences/SystemConfiguration/com.apple.airport.preferences | grep LastConnected -A 7
Show Wi-Fi Network Passwords
security find-generic-password -ga "ROUTERNAME" | grep "password:"
Package Managers
- Fink - The full world of Unix Open Source software for Darwin.
- Homebrew - The missing package manager for OS X.
- MacPorts - Compile, install and upgrade either command-line, X11 or Aqua based open-source software.
Printing
Clear Print Queue
cancel -a -
Security
Gatekeeper
Add Gatekeeper Exception
spctl --add /path/to/Application.app
Remove Gatekeeper Exception
spctl --remove /path/to/Application.app
Passwords
Generate Secure Password and Copy to Clipboard
First, install pwgen
via Homebrew, etc.
pwgen -Cs 20 1 | tr -d ' ' | tr -d '\n' | pbcopy
Wiping Data
Securely Remove File
srm /path/to/file
Securely Remove Directory
srm -r /path/to/directory/
Securely Remove Path (Force)
srm -rf /path/to/complete/destruction
System
AppleScript
Execute AppleScript
osascript /path/to/script.scpt
Basics
Restart
sudo reboot
Shutdown
sudo poweroff
Show Build Number of OS
sw_vers
Clipboard
Copy data to Clipboard
cat whatever.txt | pbcopy
Convert Tabs to Spaces for Clipboard Content
pbpaste | expand | pbcopy
Copy data from Clipboard
pbpaste > whatever.txt
Sort and Strip Duplicate Lines from Clipboard Content
pbpaste | sort | uniq | pbcopy
FileVault
Check FileVault Status
sudo fdesetup status
Information/Reports
Generate Advanced System and Performance Report
sudo sysdiagnose -f ~/Desktop/
Kernel Extensions
Load Kernel Extension
sudo kextload -b com.apple.driver.ExampleBundle
Unload Kernel Extensions
sudo kextunload -b com.apple.driver.ExampleBundle
Memory Management
Purge memory cache
sudo purge
Notification Center
Disable Notification Center
launchctl unload -w /System/Library/LaunchAgents/com.apple.notificationcenterui.plist && killall -9 NotificationCenter
Enable Notification Center
launchctl load -w /System/Library/LaunchAgents/com.apple.notificationcenterui.plist
QuickLook
Preview via QuickLook
qlmanage -p /path/to/file
Root User
Enable Root User
dsenableroot
Disable Root User
dsenableroot -d
Safe Mode Boot
Check Safe Mode Setting
nvram boot-args
Enable Safe Mode
sudo nvram boot-args="-x"
Disable Safe Mode
sudo nvram boot-args=""
Software Installation
Install PKG
installer -pkg /path/to/installer.pkg -target /
Spotlight
Disable Indexing
mdutil -i off -d /path/to/volume
Enable Indexing
mdutil -i on /path/to/volume
Erase Spotlight Index and Rebuild
mdutil -E /path/to/volume
Search via Spotlight
mdfind -name 'searchterm'
License
This work is licensed under a Creative Commons Attribution-ShareAlike 4.0 International License.