awesome-osx-command-line/README.md

491 lines
9.6 KiB
Markdown
Raw Normal View History

2015-09-23 19:18:55 -04:00
<img src="https://cdn.rawgit.com/herrbischoff/awesome-osx-command-line/master/assets/logo.svg" width="600">
2015-09-22 17:23:45 -04:00
> A curated list of shell commands and tools specific to OS X.
2015-09-22 17:48:14 -04:00
>
2015-09-24 12:11:34 -04:00
> _“You dont have to know everything. You simply need to know where to find it when necessary.” (John Brunner)_
2015-09-22 17:23:45 -04:00
2015-09-22 17:28:21 -04:00
[![Awesome](https://cdn.rawgit.com/sindresorhus/awesome/d7305f38d29fed78fa85652e3a63e154dd8e8829/media/badge.svg)](https://github.com/sindresorhus/awesome)
2015-09-23 19:20:43 -04:00
If you want to contribute, you are highly encouraged to do so. Please read the [contribution guidelines](contributing.md).
2015-09-22 17:23:45 -04:00
## Table of Contents
2015-09-24 12:11:34 -04:00
- [Appearance](#appearance)
- [Transparency](#transparency)
- [Wallpaper](#wallpaper)
- [Applications](#applications)
- [App Store](#app-store)
- [Apple Remote Desktop](#apple-remote-desktop)
- [Sketch](#sketch)
- [Backup](#backup)
- [Time Machine](#time-machine)
2015-09-24 12:11:34 -04:00
- [Developer](#developer)
- [Xcode](#xcode)
- [Disks and Volumes](#disks-and-volumes)
- [Documents](#documents)
2015-09-24 12:11:34 -04:00
- [Finder](#finder)
- [Fonts](#fonts)
- [Hardware](#hardware)
- [Hardware Information](#hardware-information)
- [Input Devices](#input-devices)
- [Keyboard](#keyboard)
- [Media](#media)
- [Audio](#audio)
- [Networking](#networking)
- [Bonjour](#bonjour)
- [DHCP](#dhcp)
- [DNS](#dns)
- [Networking Tools](#networking-tools)
- [Wi-Fi](#wi-fi)
- [Package Managers](#package-managers)
- [Printing](#printing)
- [Security](#security)
- [Gatekeeper](#gatekeeper)
- [Wiping Data](#wiping-data)
- [System](#system)
- [Basics](#basics)
- [Clipboard](#clipboard)
- [FileVault](#filevault)
- [Information/Reports](#information-reports)
- [Memory Management](#memory-management)
- [Notification Center](#notification-center)
- [Root User](#root-user)
- [Safe Mode Boot](#safe-mode-boot)
- [Kernel Extensions](#kernel-extensions)
## Appearance
### Transparency
#### Disable Transparency in Menu and Windows
```bash
defaults write com.apple.universalaccess reduceTransparency -bool true
```
#### Enable Transparency in Menu and Windows
```bash
defaults write com.apple.universalaccess reduceTransparency -bool false
```
### Wallpaper
2015-09-25 09:57:47 -04:00
#### Set Wallpaper
2015-09-24 12:11:34 -04:00
```bash
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
```bash
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
```bash
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
```
2015-09-22 17:23:45 -04:00
2015-09-24 12:11:34 -04:00
### Sketch
#### Export Compact SVGs
```bash
defaults write com.bohemiancoding.sketch3 exportCompactSVG -bool yes
```
2015-09-22 17:23:45 -04:00
## Developer
2015-09-24 12:11:34 -04:00
### Xcode
#### Install Command Line Tools Without Xcode
2015-09-22 17:23:45 -04:00
```bash
xcode-select --install
```
## Backup
### Time Machine
#### Change Backup Interval
This changes the interval to 30 minutes. The integer value is the time in seconds.
```bash
sudo defaults write /System/Library/Launch Daemons/com.apple.backupd-auto StartInterval -int 1800
```
2015-09-24 12:11:34 -04:00
## Disks and Volumes
2015-09-22 17:23:45 -04:00
2015-09-24 12:11:34 -04:00
#### Disable Sudden Motion Sensor
Leaving this turned on is useless when you're using SSDs.
```bash
sudo pmset -a sms 0
```
#### Eject All Mountable Volumes
The only reliable way to do this is by sending an AppleScript command to Finder.
```bash
osascript -e 'tell application "Finder" to eject (every disk whose ejectable is true)'
```
#### Repair File Permissions
You don't have to use the Disk Utility GUI for this.
2015-09-22 17:23:45 -04:00
```bash
sudo diskutil repairPermissions /
```
2015-09-23 16:28:51 -04:00
## Documents
#### Convert File to HTML
Supported formats are plain text, rich text (rtf) and Microsoft Word (doc/docx).
```bash
textutil -convert html file.ext
```
2015-09-22 17:23:45 -04:00
## Finder
2015-09-24 12:11:34 -04:00
#### Hide folder in Finder
2015-09-22 17:23:45 -04:00
```bash
2015-09-24 12:11:34 -04:00
chflags hidden /path/to/folder/
2015-09-22 17:23:45 -04:00
```
2015-09-24 12:11:34 -04:00
#### Show All Hidden Files
```bash
defaults write com.apple.finder AppleShowAllFiles true
```
#### Restore Default File Visibility
```bash
defaults write com.apple.finder AppleShowAllFiles false
```
2015-09-22 17:23:45 -04:00
2015-09-24 12:11:34 -04:00
#### Unhide User Library folder
2015-09-22 17:23:45 -04:00
```bash
2015-09-24 12:11:34 -04:00
chflags nohidden ~/Library
2015-09-22 17:23:45 -04:00
```
2015-09-24 12:11:34 -04:00
## Fonts
#### Clear Font Cache for Current User
To clear font caches for all users, put `sudo` in front of this command.
2015-09-22 17:23:45 -04:00
```bash
2015-09-24 12:11:34 -04:00
atsutil databases -removeUser && atsutil server -shutdown && atsutil server -ping
2015-09-22 17:23:45 -04:00
```
## Hardware
2015-09-23 19:31:00 -04:00
### Disable sudden motion sensor (useless for SSDs)
```bash
sudo pmset -a sms 0
```
2015-09-24 12:11:34 -04:00
### Hardware Information
#### List All Hardware Ports
2015-09-22 17:23:45 -04:00
```bash
networksetup -listallhardwareports
```
2015-09-24 12:11:34 -04:00
#### Show Current Screen Resolution
```bash
system_profiler SPDisplaysDataType | grep Resolution
```
### Power Management
#### Show All Power Management Settings
2015-09-22 17:23:45 -04:00
```bash
sudo pmset -g
```
2015-09-24 12:11:34 -04:00
#### Put Display to Sleep After 15 Minutes of Inactivity
```bash
sudo pmset displaysleep 15
```
#### Put Computer to Sleep After 30 Minutes of Inactivity
```bash
sudo pmset sleep 30
```
#### Check System Sleep Idle Time
```bash
sudo systemsetup -getcomputersleep
```
#### Set System Sleep Idle Time to 60 Minutes
```bash
sudo systemsetup -setcomputersleep 60
```
#### Turn Off System Sleep Completely
```bash
sudo systemsetup -setcomputersleep Never
```
2015-09-22 17:23:45 -04:00
## Input Devices
2015-09-24 12:11:34 -04:00
### Keyboard
#### Disable Auto-Correct
```bash
2015-09-24 12:11:34 -04:00
defaults write -g NSAutomaticSpellingCorrectionEnabled -bool false
```
2015-09-24 12:11:34 -04:00
#### Enable Auto-Correct
```bash
defaults write -g NSAutomaticSpellingCorrectionEnabled -bool true
```
#### Show Auto-Correct Setting
```bash
defaults read -g NSAutomaticSpellingCorrectionEnabled
```
2015-09-22 17:23:45 -04:00
## Media
2015-09-24 12:11:34 -04:00
### Audio
#### Convert Audio File to iPhone Ringtone
2015-09-22 17:23:45 -04:00
```bash
afconvert input.mp3 ringtone.m4r -f m4af
```
2015-09-24 12:11:34 -04:00
2015-09-22 17:23:45 -04:00
## Networking
2015-09-24 12:11:34 -04:00
### Bonjour
2015-09-22 17:23:45 -04:00
2015-09-24 12:11:34 -04:00
#### Disable Bonjour
2015-09-23 16:11:23 -04:00
```bash
defaults write /System/Library/LaunchDaemons/com.apple.mDNSResponder ProgramArguments -array "/usr/sbin/mDNSResponder" "-launchd"
```
2015-09-24 12:11:34 -04:00
#### Enable Bonjour
```bash
2015-09-24 12:11:34 -04:00
defaults write /System/Library/LaunchDaemons/com.apple.mDNSResponder ProgramArguments -array-add "-NoMulticastAdvertisements"
```
2015-09-24 12:11:34 -04:00
### DHCP
#### Renew DHCP Lease
2015-09-22 17:23:45 -04:00
```bash
sudo ipconfig set en0 DHCP
```
2015-09-24 12:11:34 -04:00
#### Show DHCP Info
2015-09-22 17:23:45 -04:00
```bash
ipconfig getpacket en0
```
2015-09-24 12:11:34 -04:00
### DNS
#### Clear DNS Cache
```bash
sudo dscachutil -flushcache && sudo killall -HUP mDNSResponder
```
### Networking Tools
#### Ping a Host to See Whether Its Available
```bash
ping -o github.com
```
#### Troubleshoot Routing Problems
```bash
traceroute github.com
```
### Wi-Fi
#### Show Wi-Fi Connection History
2015-09-22 17:23:45 -04:00
```bash
defaults read /Library/Preferences/SystemConfiguration/com.apple.airport.preferences | grep LastConnected -A 7
```
2015-09-24 12:11:34 -04:00
#### Show Wi-Fi Network Passwords
2015-09-22 17:23:45 -04:00
```bash
security find-generic-password -ga "ROUTERNAME" | grep "password:"
```
## Package Managers
2015-09-24 12:11:34 -04:00
- [Fink](http://www.finkproject.org) - The full world of Unix Open Source software for Darwin.
- [Homebrew](http://brew.sh) - The missing package manager for OS X.
- [MacPorts](https://www.macports.org) - Compile, install and upgrade either command-line, X11 or Aqua based open-source software.
2015-09-22 17:23:45 -04:00
## Printing
2015-09-24 12:11:34 -04:00
#### Clear Print Queue
2015-09-22 17:23:45 -04:00
```bash
cancel -a -
```
## Security
2015-09-24 12:11:34 -04:00
### Gatekeeper
#### Add Gatekeeper Exception
2015-09-22 17:23:45 -04:00
```bash
spctl --add /path/to/Application.app
```
2015-09-24 12:11:34 -04:00
#### Remove Gatekeeper Exception
2015-09-22 17:23:45 -04:00
```bash
2015-09-24 12:11:34 -04:00
spctl --remove /path/to/Application.app
2015-09-22 17:23:45 -04:00
```
2015-09-24 12:11:34 -04:00
### Wiping Data
#### Securely Remove File
2015-09-22 17:23:45 -04:00
```bash
srm /path/to/file
2015-09-24 12:11:34 -04:00
```
#### Securely Remove Directory
```bash
2015-09-22 17:23:45 -04:00
srm -r /path/to/directory/
2015-09-24 12:11:34 -04:00
```
#### Securely Remove Path (Force)
```bash
2015-09-22 17:23:45 -04:00
srm -rf /path/to/complete/destruction
```
2015-09-24 12:11:34 -04:00
2015-09-22 17:23:45 -04:00
## System
2015-09-24 12:11:34 -04:00
### Basics
#### Restart
2015-09-22 17:23:45 -04:00
```bash
2015-09-24 12:11:34 -04:00
sudo reboot
2015-09-22 17:23:45 -04:00
```
2015-09-24 12:11:34 -04:00
#### Shutdown
2015-09-22 17:23:45 -04:00
```bash
2015-09-24 12:11:34 -04:00
sudo poweroff
2015-09-22 17:23:45 -04:00
```
2015-09-24 12:11:34 -04:00
#### Show Build Number of OS
```bash
sw_vers
```
### Clipboard
#### Copy data to Clipboard
2015-09-22 17:23:45 -04:00
```bash
cat whatever.txt | pbcopy
```
2015-09-24 12:55:54 -04:00
#### Convert Tabs to Spaces for Clipboard Content
2015-09-24 12:38:36 -04:00
```bash
pbpaste | expand | pbcopy
```
2015-09-24 12:11:34 -04:00
#### Copy data from Clipboard
2015-09-23 16:18:00 -04:00
```bash
2015-09-24 12:11:34 -04:00
pbpaste > whatever.txt
2015-09-23 16:18:00 -04:00
```
2015-09-24 12:35:59 -04:00
#### Sort and Strip Duplicate Lines from Clipboard Content
```bash
pbpaste | sort | uniq | pbcopy
```
2015-09-24 12:11:34 -04:00
### FileVault
#### Check FileVault Status
2015-09-23 16:23:58 -04:00
```bash
2015-09-24 12:11:34 -04:00
sudo fdesetup status
2015-09-23 16:23:58 -04:00
```
2015-09-24 12:11:34 -04:00
### Information/Reports
#### Generate Advanced System and Performance Report
2015-09-22 17:23:45 -04:00
```bash
2015-09-24 12:11:34 -04:00
sudo sysdiagnose -f ~/Desktop/
2015-09-22 17:23:45 -04:00
```
2015-09-24 12:59:05 -04:00
### Kernel Extensions
#### Load Kernel Extension
```bash
sudo kextload -b com.apple.driver.ExampleBundle
```
#### Unload Kernel Extensions
```bash
sudo kextunload -b com.apple.driver.ExampleBundle
```
### Memory Management
2015-09-24 12:11:34 -04:00
#### Purge memory cache
2015-09-22 17:23:45 -04:00
```bash
2015-09-24 12:11:34 -04:00
sudo purge
2015-09-22 17:23:45 -04:00
```
2015-09-24 12:11:34 -04:00
### Notification Center
#### Disable Notification Center
2015-09-22 17:23:45 -04:00
```bash
2015-09-24 12:11:34 -04:00
launchctl unload -w /System/Library/LaunchAgents/com.apple.notificationcenterui.plist && killall -9 NotificationCenter
2015-09-22 17:23:45 -04:00
```
2015-09-24 12:11:34 -04:00
#### Enable Notification Center
2015-09-22 17:23:45 -04:00
```bash
2015-09-24 12:11:34 -04:00
launchctl load -w /System/Library/LaunchAgents/com.apple.notificationcenterui.plist
2015-09-22 17:23:45 -04:00
```
2015-09-24 12:11:34 -04:00
### Root User
#### Enable Root User
2015-09-22 17:23:45 -04:00
```bash
2015-09-24 12:11:34 -04:00
dsenableroot
2015-09-22 17:23:45 -04:00
```
2015-09-24 12:11:34 -04:00
#### Disable Root User
2015-09-22 17:23:45 -04:00
```bash
2015-09-24 12:11:34 -04:00
dsenableroot -d
2015-09-22 17:23:45 -04:00
```
2015-09-24 12:11:34 -04:00
### Safe Mode Boot
#### Check Safe Mode Setting
2015-09-22 17:23:45 -04:00
```bash
2015-09-24 12:11:34 -04:00
nvram boot-args
2015-09-22 17:23:45 -04:00
```
2015-09-24 12:11:34 -04:00
#### Enable Safe Mode
2015-09-22 17:23:45 -04:00
```bash
2015-09-24 12:11:34 -04:00
sudo nvram boot-args="-x"
2015-09-22 17:23:45 -04:00
```
2015-09-24 12:11:34 -04:00
#### Disable Safe Mode
2015-09-22 17:23:45 -04:00
```bash
2015-09-24 12:11:34 -04:00
sudo nvram boot-args=""
2015-09-22 17:23:45 -04:00
```
2015-09-22 17:42:05 -04:00
## License
<a rel="license" href="http://creativecommons.org/licenses/by-sa/4.0/"><img alt="Creative Commons License" style="border-width:0" src="https://i.creativecommons.org/l/by-sa/4.0/88x31.png" /></a><br />This work is licensed under a <a rel="license" href="http://creativecommons.org/licenses/by-sa/4.0/">Creative Commons Attribution-ShareAlike 4.0 International License</a>.