In times of modern graphical user interfaces, it seems antiquated to enter commands into a terminal window using the keyboard. After all, macOS has always been extremely easy to use with the mouse or the trackpad. No wonder then, if the terminal window in the daily work of most users nishes a niche existence. On closer examination, however, it quickly turns out to be a useful supplement. For example, you can make some settings that you will look for in the system settings in vain. With just a few easy-to-learn basic skills, you will be able to benefit from the terminal’s capabilities.
Starting the Terminal
You can find the terminal in your “Applications” folder in the Subcategory “Utilities”. It is, like any other program, started by a double-click. Alternatively, use the key combination [cmd] + [Leertaste] to open the Spotlight search, type in “Terminal” and start the program with the Enter key.
Navigate through directories
The Terminal offers, to put it simply, text-based access to the operating system. Use a command prompt to issue commands that combine with additional options. This prompt appears as follows:
Computer name: Current directory Username $
When you first start up, you are usually in your user directory, which is marked with a tilde (~). The pwd (print working directory) command tells you which directory you are in. No additional options are required.
The ls (list) command displays the contents of the current directory. By specifying options, you determine how the directory content is listed. So ls -l produces an output in list form. Ls -a also displays hidden objects. Of course, you can also combine these options (for example, ls -la). Note that system folder names are given in English (ie desktop instead of desktop, pictures instead of pictures, and so on).
Use the cd path (change directory) command to navigate directories. Of course, you can also use full path information, such as cd Music / iTunes / “iTunes Media”. A special feature are paths that contain spaces. Enclose these, as shown in the example, with quotation marks.
You can easily change to the higher-level directory with cd .., no further path information is required. Especially easy is the return to your home folder. All it takes is a simple cd without any further options.
Surely you have come across a file whose purpose was hidden from you at first sight. If the menu item “Information” of the Finder does not provide further information, the terminal may help. Use cd to navigate to the desired file and invoke the file command followed by the filename (for example, file unknown_file.xyz). Typically, this gives you much more detail than the finder will provide.
Use less (also followed by the file name) to display the contents of a file. Since the screen output takes place exclusively in the terminal, you do not need to open another program. Although less is intended for viewing text files, it can also display the contents of binaries. This may also help to determine the content or purpose of a file. The navigation is done as usual with the arrow keys. The viewer is terminated by pressing the [q] key.
Changing Hidden Settings
Most programs on macOS store their user preferences in “.plist” files. These are located in the folders / Library / Preferences / and ~ / Library / Preferences. But beware! Careless changes or the deletion of these files leads to an unusable system in the worst case!
However, not all of these settings are always available via the respective option dialogs. In this case, use the defaults command to make changes to inaccessible settings. This is used with the following scheme:
defaults mode domain key value
The parameter mode determines the type of access. Pass read to read or write to write value. The program whose settings you want to change is indicated by the domain assigned to it. Sounds complex? It’s not at all: for Apple Mail this is for example com.apple.mail.plist, for the Finder com.apple.finder.plist. With NSGlobalDomain you address the global system settings. The actual setting represents a key / value pair. The following tips show how easy it is.
The terminal is a practical tool that focuses on speed and efficiency. Commands are therefore executed immediately without any ifs or buts. Since security queries are not part of the agenda, you should always pay attention to the correct spelling and just look at critical commands again. A wrong path may possibly lead to data loss – and in the worst case even to an unusable system.
Turn Key Repeat On
With OS X 10.7 (Lion), Apple has introduced iOS-known functionality that makes it easier to enter umlauts and accented characters. If you press, for example, the key [o] for almost half a second, a corresponding selection menu appears. This is convenient, but not always desirable. If you would like to deactivate this feature, however, you will search for a suitable setting in vain. Here the terminal helps. The power-off command is as follows:
defaults write NSGlobalDomain ApplePressAndHoldEnabled -boolfalse
Depending on the type of setting, a particular key type will apply. The most common ones are bool (Boolean value, sort of “on / off”), int (integer), float floating-point number, and string (string). If you omit the type, string is automatically used. In the example just shown, the key ApplePressAndHoldEnabled of type bool is set to false, so the feature is turned off. If you want to turn it on again, set the value to true. For the change to take effect, you must log out, log in, or reboot.
Invisible files permanently visible
By default, macOS does not display hidden files and folders. This makes perfect sense, because so just newcomers are prevented from accidentally delete important files. Nevertheless, it occasionally happens that you need access to it. Since macOS Sierra, there is the handy shortcut [cmd] + [shift] + [.]with which hidden content can be displayed. The disadvantage, however, is that this setting automatically resets after a reboot or user logoff. Successively enter the following two commands to correct them:
defaults write com.apple.finder AppleShowAllFiles -bool truekillall Finder
The effect will not be visible until you restart the Finder. Killall is used to immediately terminate a running program (more precisely, a process). The instruction shown thus closes all Finder windows and all related background processes. MacOS automatically restarts the Finder – so you do not have to worry about it. Subsequently, all previously hidden files are displayed permanently. If you want to hide the files again, repeat the commands shown and replace the value true with false.
Screenshots: there is more!
The included program “Screenshot” probably every user has already used. It is easy to use and fully adequate in most situations. But even if you regularly take screenshots, the presets may not be what you want. For example, did you know that you can automatically convert screen captures to PDF files? This works as follows:
defaults write com.apple.screencapture type pdf
You can use the key type to specify the desired output format. Possible values are jpg, png, tiff and pdf. This change takes effect immediately and does not require a restart.
The fact that windows cast a shadow is not only visually pleasing, but also helps to maintain an overview of several open windows. But for screenshots, this is not always appropriate and can even be annoying. Instead of cutting out the shadows in an image editor, you can also exclude them from the capture:
defaults write com.apple.screencapture disable-shadow -bool truekillall SystemUIServer
Again, the changes not immediately effective. Only after a restart of the process “SystemUIServer”, the shadows permanently disappear from the screenshots.
It is not always desirable to have screen shots stored on the desktop. Especially if you have the “Desk & Documents” option enabled in your iCloud settings, a different location is desirable. Again, the path passes through the terminal:
defaults write com.apple.screencapture location ~ / desired_path
Note that the folder you specify using / desired_path must also be present and that the case is the same.
Save on typing
Using the cursor keys, you can easily navigate through the most recently entered commands and save yourself some typing. Also helpful is the history command, which displays the last 500 commands you have typed.
There is also support for entering paths: Pressing the [tab] button will autocomplete. It is usually sufficient to enter only the first two characters of the directory name before.
It is even easier if Finder and Terminal work together: Just drag a file or a folder from the Finder into the terminal and the complete path will appear.