Family Best Time >> Electronics

Top 11 Terminal Command Tricks for Mac You Need to Know

Apple's macOS platform includes Terminal, which is equivalent to the command prompt in the Windows operating system. Since macOS is UNIX-based, Terminal can give you the impression of a dangerous tool where one wrong command can destroy your system. Of course, this is only valid to a certain extent. There are plenty of harmless commands you can use to customize the interface and other macOS settings.

Contents1. Open folders 2. Change the default screenshot recording location3. Change screenshot image type4. Show hidden files5. Switch off the dashboard6. Download files7. Ditto for backups
8. Always show file path in Finder9. Power chime when connecting charger10. Prevent your Mac from sleeping11. Check Your Mac's AvailabilityUsing the Terminal is Fun Top 11 Terminal Command Tricks for Mac You Need to Know

The Terminal on macOS can be extremely useful for tweaking your Mac's performance. Now, it entirely depends on what you want to achieve. In case you are worried about using it, you can always make yourself comfortable using some simpler tricks. Here are the 11 best terminal command tricks to try on your Mac.

Note: When selecting/copying an order, be sure to scroll all the way to the right to select the entire order in the gray box. Otherwise, the partial commands will not work as expected.

1. Open folders

One of the coolest ways to get familiar with the terminal is to use it to open files and folders. I know clicking Finder will do the same thing. However, using Terminal, you can open a specific folder or file without exposing your file structure to anyone.

Let's say you want to open your Documents folder. Then you can type the following command and then press Enter.

Open ~/Documents

And this opens my Documents folder. There is a DOCX file in there. I can also use Terminal to open it. For this you need to type the command with some requirements – the respective file path:

Open -a "Application Name" /Path/to/File

Top 11 Terminal Command Tricks for Mac You Need to Know

So, to open the DOCX file in my Mac's Documents folder, I typed the command below, then hit Enter:

Open -a "Microsoft Word" ~/Documents/SoP_Prajith_New.docx

This opens the specific file using the preset program. You can also use the wildcard character (*.extension) instead of the full filename. However, if you have multiple files with the same extension, it may freeze your Mac a bit.

2. Change the default screenshot recording location

By default, macOS Mojave stores screenshots on the Mac desktop. Now, if you have iCloud sync enabled, which I'm sure you do, the download continues on your account. Luckily, you can change where screenshots are saved instead of cluttering your desktop.

Here is the command you need to type before hitting Enter:

defaults write com.apple.screencapture location ~/Downloads

In the above command you can provide any specific file location instead of ~/Downloads as shown.

Top 11 Terminal Command Tricks for Mac You Need to Know

After hitting enter, I need to reset the SystemUIServer for the changes to take effect immediately. So feed the following command.

killall SystemUIServer

Although not required, I recommend restarting your Mac.

3. Change screenshot image type

The macOS saves screenshots in JPG format by default. You can change this to also save them in PNG or PDF format. Here's how to do it quickly with this specific command:

defaults write com.apple.screencapture type PNG

After that you have to kill the SystemUIServer again. Most commands that require system changes should force the SystemUIServer to shut down. So do it fast.

killall SystemUIServer

Now your new screenshots will be saved in PNG format. Note that PNG files are generally larger than JPG files. So keep an eye on the storage space they consume.

4. Show hidden files

Have you tried looking for the option to allow Finder to show hidden files? Well, it is more difficult than choosing hidden files on Windows. I keep forgetting how to enable this. Luckily, there's a handy command that lets you do this in seconds.

defaults write com.apple.finder AppleShowAllFiles -bool TRUE
Top 11 Terminal Command Tricks for Mac You Need to Know

After that, you need to force quit Finder.

killall Finder

You should now see lots of hidden files in Finder. They would be grayed out but still visible. If you undo this change, you must change TRUE to FALSE in the command.

5. Turn off the dashboard

Apple promoted the Dashboard view for quick access to the calculator and sticky notes. I bet you rarely use it because you can launch Calculator app or Sticky Notes app using Mission Control of Spotlight. So you can turn it off and not have to worry about opening it by mistake.

Here is the command to disable the dashboard.

defaults write com.apple.dashboard mcx-disabled -boolean TRUE

Then you need to kill the Dock for the changes to be properly applied.

killall Dock

Now I don't have to worry about accidentally opening the dashboard. If you want to turn it back on, replace TRUE with FALSE in the command.

6. Download files

Did you know you can download files using Terminal? Yes, you don't need to let the browser work just for this file. The only requirement here is that you must have the file download link. The command syntax is therefore:

curl -0 download link

First, navigate to the folder where you want to upload the file. To do this, you need to switch to the Downloads directory.

Top 11 Terminal Command Tricks for Mac You Need to Know

cd ~/Downloads

After that, you can feed the command to download the VLC for macOS from the official site. It would look something like this:

curl -O https://get.videolan.org/vlc/3.0.7.1/macosx/vlc-3.0.7.1.dmg
Note: There is a letter O in the command and not the 0 (zero).

7. Ditto for backups

Copying files and making backups on macOS is quite fast, thanks to SSDs and flash storage. However, copying a large amount of data takes some time. Fortunately, Terminal offers a useful command for copying files. Here's how to do it while monitoring the names of the files the command copies.

same -V /currentpath/ /new/path/

So I want to copy the DMG downloaded in the previous section to the desktop.

ditto -V ~/Downloads/vlc-3.0.7.1.dmg ~/Desktop
Top 11 Terminal Command Tricks for Mac You Need to Know

That should do the needful. If you want to copy the files to an external drive, you must provide the destination path correctly.

8. Always show file path in Finder

If you recently switched from Windows, you would have noticed that the Finder on macOS does not display the file path like Windows Explorer. However, you can force Finder to show you the file path with this command:

defaults write com.apple.finder _FXShowPosixPathInTitle -boolean true
Top 11 Terminal Command Tricks for Mac You Need to Know

After pressing Enter, you must stop the Finder.

killall Finder

After pressing Enter, the Finder will relaunch. Then you should see the file paths at the top of the Finder window.

9. Power chime when connecting charger

Have you ever connected the MagSafe charger to your Mac but forgot to turn on the power switch? I lost count. Luckily, I came across this useful command that provides an audio feedback chime whenever I connect the MagSafe charger.

Enter this command in the terminal and press Enter.

defaults write com.apple.PowerChime ChimeOnAllHardware -bool true; open /System/Library/CoreServices/PowerChime.app

10. Prevent your Mac from sleeping

Often you download a large file and you don't want your Mac to go to sleep. If it is a temporary requirement, a simple command can make it happen. Just type the following command, hit enter, and walk away from your Mac.

caffeinate -u -t 600
Top 11 Terminal Command Tricks for Mac You Need to Know

In this command, the number 600 means seconds. So, with this command, the Mac will not sleep for 10 minutes (600 seconds). You can enter a relevant number of seconds or just the word "caffeinate to prevent your Mac from sleeping.

However, if you close this terminal window, the command will stop running and the Mac will go to sleep at a preset time.

11. Check availability of your Mac

Wondering how long it's been since you restarted your Mac? A simple restart can sort a lot of things in order and improve your Mac's performance. Here is a command to check how long your Mac has been running without restarting or shutting down

uptime
Top 11 Terminal Command Tricks for Mac You Need to Know

This should give you all the details with a timestamp.

Using the terminal is fun

The Terminal is an absolute pleasure to use and tinker with in macOS. However, we strictly advise against using random commands provided by unverified sources or strangers. Other than that, these commands should run on the latest macOS Mojave update to the latest versions.

You should always double-check terminal commands that involve deleting, deleting, or disabling any service. If you stick to our list, you'll be sure to use Terminal like a pro.

Then: Tired of the same old lock screen on your Mac? Here is a nifty guide that will show how to customize the lock screen on your Mac OS Mojave running Mac.