9 terminal tricks on Mac that everyone should know
The command line, which can usually be accessed through the Terminal application, is usually considered the lot of advanced users, but this does not mean that this is some kind of incredibly complex thing in itself. This is proved by the following selection of Terminal capabilities, which can be useful to the widest range of makovodov.
Some of these features may require the presence of Xcode in the system, which can be installed for free from the Mac App Store (we are forced to warn, however, that it weighs quite a lot).
Prevent screensaver launch and hibernate using caffeinate
Appearing in OS X Mountain Lion, the caffeinate command is a console equivalent of the well-known Caffeine utility. The principle of operation is very simple - from running caffeinate, your Mac will not go into sleep mode or activate a screensaver. It can also be started without additional parameters, but it is possible to limit the time of its operation with a timer, for example:
caffeinate -t 3600
Extract files from PKG with pkgutil
Need to extract a file from a batch .pkg file? Or see the contents of the PKG without installation? Use pkgutil:
pkgutil --expand package.pkg ~/Desktop/
Free up some memory with purge
The purge command forcibly clears the disk cache and memory cache, which has an effect similar to restarting the computer. Although some say that the purge has a placebo effect rather, it copes well in pulling system memory from the Inactive category into the Available category, which adds speed to the system in situations where the memory is running out. Using this command is easy.
... and wait a little while for the changes to take effect, it usually happens faster on Macs with an SSD.
Use open to run multiple copies of the same application.
You may already know that you can start GUI applications from the Terminal using the open command, but did you know that you can run multiple copies of the application by simply adding the -n flag? This example launches a new copy of Safari.
open -n /Applications/Safari.app/
Update OS X without App Store
Want to upgrade without launching the not always fast Mac App Store application? At your disposal command line and softwareupdate command:
sudo softwareupdate -i -a
View a list of all the files you have ever downloaded from the web.
Forgot what and where did you appear in the "Downloads" folder? Quarantine System Service keeps track of all your downloads in its database, and you just need to contact it with a corresponding request. The sqlite3 command with the following parameters will bring you a complete list:
sqlite3 ~/Library/Preferences/com.apple.LaunchServices.QuarantineEventsV* 'select LSQuarantineDataURLString from LSQuarantineEvent' |more
If the existence of these records strains you, you can clear them with the following command:
sqlite3 ~/Library/Preferences/com.apple.LaunchServices.QuarantineEventsV* 'delete from LSQuarantineEvent'
Hide files and folders from the Finder using chflags
Want to hide a file or folder from random eyes? Use chflags to make them invisible in the OS X GUI:
chflags hidden /path/to/file/or/folder/
Fortunately (or unfortunate), the hidden object will still be visible with the ls command. To return “visibility” use the nohidden flag:
chflags nohidden /path/to/unhide/
Automatic substitution of long paths by dragging
If you drag any file from the Finder to the Terminal, its full path will appear in the command line. The best way to use this function is in combination with some command, for example, editing:
sudo vi (перетащите сюда файл, чтобы вставить путь к нему)
Create a password-protected zip archive
When sending valuable files, for example, a mail attachment, it is useful to protect them. The easiest way is to put them in a password-protected archive file, for which you need to use the -e flag:
zip -e protected.zip /file/to/protect/