9 tricks of the terminal in the Mac, which 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 incredibly complex thing in itself. This is proved by the following selection of the Terminal's capabilities, which can be useful to the widest range of makovodov.
Some of these features may require the Xcode system, which can be installed free of charge from the Mac App Store (forced to warn, though, that it weighs a lot).
Prevent the launch of the screensaver and the transition to sleep with caffeinate
The caffeinate command, which appeared in OS X Mountain Lion, is a console analog of the well-known utility Caffeine. The principle of operation is very simple - with running caffeinate your Mac will not go into hibernation mode or activate the screensaver. It can be run without additional parameters, but you can also limit its time to the timer, for example:
caffeinate -t 3600
Extract files from PKG using pkgutil
Is there a need to pull the file out of the .pkg batch file? Or look at the contents of PKG without installing it? Use pkgutil:
pkgutil --expand package.pkg ~/Desktop/
Free up some memory with purge
The purge command forcibly cleans the disk cache and cache, which gives an effect similar to a computer restart. Although some say that the purge is more likely to have a placebo effect, it does manage to pull the system memory from the "Inactive" category to the "Available" category, which will add speed to the system in situations where the RAM is running out. Use this command is very simple
... and wait a little while for the changes to take effect, usually this happens faster on Macs with SSD.
Use open to run multiple copies of the same application
Perhaps you already know that you can run GUI applications from the Terminal using the open command, but do you know that you can run multiple copies of the application simply by adding the -n flag? This example launches a new copy of Safari.
open -n /Applications/Safari.app/
Update OS X without App Store
Do you want to upgrade without running the Mac App Store? At your command is a command line and the softwareupdate command:
sudo softwareupdate -i -a
View a list of all the files that you have ever downloaded from the Web
Forgot what and where did you come from in the Downloads folder? The Quarantine system service keeps track of all your downloads in your database, and you just have to consult it with the corresponding query. The sqlite3 command with the following parameters will list the complete list:
sqlite3 ~/Library/Preferences/com.apple.LaunchServices.QuarantineEventsV* 'select LSQuarantineDataURLString from LSQuarantineEvent' |more
If you are "stressed" by the existence of these records, they can be cleared by the following command:
sqlite3 ~/Library/Preferences/com.apple.LaunchServices.QuarantineEventsV* 'delete from LSQuarantineEvent'
Hide files and folders from the Finder using chflags
Do you 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 unfortunately), the hidden object will still be seen by 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, the full path is displayed on the command line. The best way to use this function is in combination with some command, for example, editing:
sudo vi (перетащите сюда файл, чтобы вставить путь к нему)
Create 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 an archive file, closed with a password, for which you need to use the -e flag:
zip -e protected.zip /file/to/protect/