The Terminal is the most powerful application within OS X. It is your gateway into the “OS within the OS”, the UNIX core of OS X. Hidden tricks, hacks, workarounds and functions are loaded into the Terminal’s commands. The following list of ten useful Terminal tricks is by no means the only tricks, in fact there’s probably hundreds of them, many in previously written articles. I decided to compile a quick list of ten Terminal tricks based on their usefulness.
1. Ejecting CDs/DVDs.
Sometimes a CD or DVD just does not want to eject. A recommended method to force them out is to reboot and hold down the trackpad button. However, before you have to restart your computer, try opening up the Terminal and typing:
diskutil eject (device)
The device can be either an entry in the following forms:
– Node Entry: /dev/disk#
– Disk Identifier: disk#s#
– Volume Mount Point: /Volumes/(VolumeName)
– The UUID – Example: 11111111-2222-3333-4444-555555555555.
2. Ejecting / Unmounting Network Volumes.
If you connect to AFP or SMB(Windows) fileshares, you know about how sometimes they get stuck and refuse to eject. Rather than deal with waiting until the connection times out, type the following into the Terminal:
umount -f /Volumes/(VolumeName)
3. Command Line Software Update.
While not a new trick, this is the most useful way to update OS X without all of the hassles of the GUI software update (Entering the admin password again and again). This trick is also wonderful in script form when you need to remotely update multiple OS X machines remotely. We will sudo this one to avoid any administrator password issues.
sudo softwareupdate -i -a
Note: You can modify this command to either ignore or install only certain updates. Read the man page for the commands.
4. Show Hidden Files.
This one is useful when you need to search for and modify anything hidden in OS X. It will also expose OS X’s UNIX directories for browsing in the finder. Replace TRUE with FALSE to hide everything again.
defaults write com.apple.finder AppleShowAllFiles TRUE
5. Reset the “Open With” menu.
Over time the “Open With” menu can get cluttered. Solve this issue by resetting it. Type the following:
/System/Library/Frameworks/CoreServices.framework/Versions/A/Frameworks/LaunchServices.framework/Versions/A/Support/lsregister -kill -r -domain local -domain system -domain user
6. Quickly Convert Document Formats.
The Terminal can quickly convert documents to and from the following formats: .txt, .html, .rtf, .rtfd, .doc, .docx, .wordml, .odt, and webarchive. Type the following to do the conversion:
textutil -convert (Format) (Filename)
7. Securely Web Browsing with SSH.
You will need a computer to connect to for this one along with its IP. Set your browser’s proxy settings to use socks proxy, localhost for the address and 8080 for the port. Once you have that set up, enter into Terminal the following command:
ssh -l (Username) -D8080 (IP)
8. Automatically expanding the Print dialogue box.
OS X likes to set you up with the simplified Print dialogue. While useful for quick prints, if you need to do anything custom you need to press the arrow key next to the printer tab. I personally prefer this expanded dialogue to always show itself, as I often need to adjust settings. With the Terminal, this is not a problem. Just type:
defaults write -g PMPrintingExpandedStateForPrint -bool TRUE
9. Automatically expanding the Save dialogue box.
Just like with the print dialogue, the Save dialogue always defaults to the simplified version. You can change that too by typing the following:
defaults write -g NSNavPanelExpandedStateForSaveMode -bool TRUE
10. Disable Time Machine’s “Use this Disk as Backup Drive?” prompt.
While Time Machine is a great feature, it can get seriously annoying. Want it to stop it from asking you “Do you want to use this disk as a backup disk?” everytime you plug in an external drive? Just type the following into the Terminal:
defaults write com.apple.TimeMachine DoNotOfferNewDisksForBackup -bool YES