Table of contents:

20 Terminal commands in macOS that will come in handy
20 Terminal commands in macOS that will come in handy
Anonim

Learn how to make working on your Mac easier and more convenient.

20 Terminal commands in macOS that will come in handy
20 Terminal commands in macOS that will come in handy

All macOS functions are thought out to the smallest detail and their settings are optimal for most users. However, with the help of the "Terminal" commands, the behavior of the system can be changed, and its capabilities can be expanded. And in some cases it can be very useful.

To apply or cancel the settings, launch the "Terminal" from the "Applications" → "Utilities" folder and enter the following commands using the combinations Cmd + C, Cmd + V.

Show hidden files and folders in Finder

macOS commands: Show hidden files and folders
macOS commands: Show hidden files and folders

It is not often, but still there is a need to delve into hidden files on the disk. By default, they do not appear in the Finder, and you have to use a special command to see them.

How to turn on:

defaults write com.apple.finder AppleShowAllFiles -bool TRUE && killall Finder

How to disable:

defaults write com.apple.finder AppleShowAllFiles -bool FALSE && killall Finder

Hiding files and folders

If you wish, you can also hide private data on the disk from prying eyes. This is done by the command chflags … After it, you need to enter the path to the file or folder that you want to hide. In order not to bother with entering the path, you can simply type in the command, and then drag the desired folder into the "Terminal" window.

How to turn on:

chflags hidden ~ / Desktop / Secret Folder

How to disable:

chflags nohidden ~ / Desktop / Secret folder

Copying text in Preview

Pressing the spacebar in Finder opens a quick view of files. This makes it very convenient to check the content of text documents. But the selection does not work in this window - to copy the text, you have to open the document. In order not to waste time on this, activate the selection function for quick viewing.

How to turn on:

defaults write com.apple.finder QLEnableTextSelection -bool TRUE && killall Finder

How to disable:

defaults write com.apple.finder QLEnableTextSelection -bool FALSE && killall Finder

Downloading files without a browser

You don't need to use Safari or Chrome to download a file from a link from the Internet. Sometimes it is much faster and easier to do it through the "Terminal" using the command curl.

How to use:

curl -O

Create a file of any size

It is convenient to test the speed of data transfer over a network or from external media by copying files. It takes a long time to search for a movie or image of a suitable size for this, so it is much easier to create a test file using the command mkfile … You can set the desired size using numbers and symbols b, k, m or gmeaning bytes, kilobytes, megabytes, and gigabytes, respectively.

How to use:

mkfile 1g test.abc

View all active processes

macOS commands: Active processes
macOS commands: Active processes

To monitor system resources in macOS, there is a program that is called that. It is quite convenient and informative, but you can just as well view the most resource-intensive processes in the "Terminal".

How to use:

top

Disable shadows in screenshots

A distinctive feature of screenshots in macOS is the beautiful shadows around them. In some situations, they interfere and you want to remove them. To do this, just enter the following command.

How to disable:

defaults write com.apple.screencapture disable-shadow -bool TRUE && killall SystemUIServer

How to turn on:

defaults write com.apple.screencapture disable-shadow -bool FALSE && killall SystemUIServer

Change the format of screenshots

By default, all screenshots are saved in PNG. This format allows you to achieve high quality, but requires a lot of space for files. If you often export captured screenshots from-p.webp

How to turn on:

defaults write com.apple.screencapture type JPG && killall SystemUIServer

How to disable:

defaults write com.apple.screencapture type PNG && killall SystemUIServer

Besides JPG, macOS also allows you to select TIFF or PDF for example.

Change where screenshots are saved

Taking a lot of screenshots and having no time to delete them from your desktop? Create a separate folder and save screenshots to it. And such a command will help with this.

How to use:

defaults write com.apple.screencapture location ~ / Desktop / Screenshots && killall SystemUIServer

How to get back:

defaults write com.apple.screencapture location ~ / Desktop && killall SystemUIServer

Speed up dock animation

When you need to focus on your work, it's convenient to hide and open the dock by hovering your mouse over the bottom of the screen. By default, the panel appears with a delay of 0.7 seconds, but this is easy to change. A noticeable acceleration is observed already at a delay of 0.5 seconds. But if this is a lot, you can completely remove the delay by setting zero.

How to turn on:

defaults write com.apple.dock autohide-time-modifier -float 0.5 && killall Dock

How to disable:

defaults write com.apple.dock autohide-time-modifier -float 0.7 && killall Dock

Adding a separator to the dock

macOS commands: Add a separator to the dock
macOS commands: Add a separator to the dock

There is a separator in the dock only next to the basket, all other icons are displayed in a row. And sometimes, when there are a lot of them, it becomes quite difficult to find the right ones. To make the dock more neat by sorting programs, for example, by category, you can use the separator.

How to add:

defaults write com.apple.dock persistent-apps -array-add '{"tile-type" = "spacer-tile";}' && killall Dock

How to remove:

To remove the separator, you just need to pull it out of the dock like any other icon that it, in fact, is.

Lock screen message

And this trick will come in handy in case of losing your computer or for pranking colleagues. You can add any text to the login screen with the following command.

How to turn on:

sudo defaults write /Library/Preferences/com.apple.loginwindow LoginwindowText "Your message"

How to disable:

sudo defaults delete /Library/Preferences/com.apple.loginwindow

Speaking text

MacOS has a built-in speech synthesizer that can read the given text. To force the device to speak, you need to enter a special command in the "Terminal", adding the desired text or the path to the document to it.

How to use:

say "Hello Lifehacker!"

say -f ~ / Documents / fairytale.txt

Calendar view

macOS commands: Customize your calendar
macOS commands: Customize your calendar

The calendar is displayed in the application of the same name, as well as in the date and time settings. Another way to quickly view it is with the command cal in the "Terminal". By default, it shows the current month, but if you add a year to it, you can see the full calendar.

How to use:

cal 2018

Freeing up RAM

The system itself does a good job of managing memory, but when the RAM is clogged to capacity and the computer starts to slow down, you can forcefully improve the situation by clearing the application cache. This is done by the command purgewhich will require you to enter the administrator password.

How to use:

purge

Checking Mac Uptime

Apple computers run smoothly for weeks or even months. Sometimes it is interesting to know how much time has passed since the last power-on. The following command will answer this question.

How to use:

uptime

Prevent from going to sleep

When a task is performed on a Mac without pressing keys or touching the trackpad, after a while, the computer goes to sleep and the process pauses. You can avoid this by prohibiting the transition to this mode using the settings or using a special utility. However, there is an easier way - the command caffeinate.

How to turn on:

caffeinate

How to disable:

To return to the current energy saving settings, you need to leave the execution of the process in the "Terminal" using the keyboard shortcut Ctrl + C.

Mac stress test

If the computer crashes and the problem only manifests itself under load, it can be easily identified using the following command. It loads all processor cores at 100% until you stop its execution.

How to turn on:

yes> / dev / null && yes> / dev / null && yes> / dev / null && yes / dev / null &&

How to disable:

killall yes

Instant reboot or shutdown

A standard Mac shutdown requires saving all open documents and takes additional time. If you are sure that everything is saved, and you want to turn off your computer without delay, use the following commands.

To turn off enter:

sudo shutdown -h now

To reboot:

sudo shutdown -r now

Auto reboot when freezing

Occasionally, the Mac may freeze and become unresponsive. In this case, you need to force restart the computer while holding down the power button. After entering this command, the system will automatically reboot after failures.

How to turn on:

sudo systemsetup -setrestartfreeze on

How to disable:

sudo systemsetup -setrestartfreeze off

Recommended: