Top 11 Terminal Command Tricks for Mac That You Should Know
Apple's macOS platform includes Terminal, the equivalent of the Windows command prompt. Because macOS is based on UNIX, it can give you the impression of a dangerous tool in which an incorrect command can destroy your system. Of course, this is only valid to a certain extent. Many commands can be used to customize the interface and other macOS settings.
The terminal on macOS can be extremely useful for improving the performance of your Mac. Now, everything depends on what you want to achieve. In case you are worried about using it, you can always put yourself at ease using harmless tips. Here are the top terminal control tips to try on your Mac.
1. Open the folders
One of the best ways to familiarize yourself with the device is to use it to open files and folders. I know that clicking Finder will do the same. However, using Terminal, you can open a specific folder or file without exposing your file structure to anyone.
Say you want to open your documents folder. Then you can type the following command, then press Enter.
Open ~/Documents
And that opens my Documents folder. There is a DOCX file in this folder. I can also use Terminal to open it. For this, you must type the command with certain requirements:
Open -a "Name of the application" / Path / To / File
So, to open the DOCX file in the Documents folder of my Mac, I have to type this command, then press Enter:
Open -a "Microsoft Word" ~/Documents/SoP_Prajith_New.docx
This opens the specific file using the predefined program. You can also use the wildcard (* .extension) instead of the full file name. However, if you have multiple files with the same extension, your Mac may freeze a bit.
2. Change the default backup screen capture location
By default, macOS Mojave stores screenshots on the Mac's desktop. Now, if you have synced iCloud sync, which I'm sure to do, the download will continue on your account. So you can change the location of saving screen captures instead of overloading your desktop.
Here is the command you need to type before pressing Enter:
defaults write com.apple.screencapture location ~/Downloads
In the above command, you can provide any specific file location instead of ~ / Downloads as shown.
After pressing Enter, I must reset SystemUIServer for the changes to take effect immediately. Then, enter the following command.
killall SystemUIServer
Although this is not mandatory, I recommend that you restart your Mac.
3. Change the type of capture image
The macOS saves the screenshots in the default JPG format. You can also change this to save as PNG or PDF. Here's how to do this quickly with this specific command:
defaults write com.apple.screencapture type PNG
After that, you must kill SystemUIServer again.
Most commands that require system changes must force SystemUIServer to stop. So be quick.
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 amount of storage space they consume.
4. Show hidden files
Have you tried searching for the option allowing the Finder to display hidden files? Well, it's harder than choosing the hidden files from the show on Windows. I always forget how to activate this. Fortunately, there is a useful command that makes it possible in seconds.
defaults write com.apple.finder AppleShowAllFiles -bool TRUE
After that, you must force the Finder to close.
killall Finder
You should now see a lot of hidden files in the Finder. They would be gray but still visible. If you cancel this change, you must set TRUE to FALSE in the command.
5. Turn off the dashboard
Apple promoted the Dashboard view for quick access to calculator and sticky notes. I bet you rarely use this one because you can run the Calculator application or Sticky Notes application with the help of 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 turn off the dashboard.
defaults write com.apple.dashboard mcx-disabled -boolean TRUE
Then, you must remove the Dock for the changes to be correctly applied.
killall Dock
Now I do not have to worry about accidentally opening the dashboard. If you want to enable it again, set TRUE to FALSE in the command.
6. Download files
Did you know that you can download files using the terminal? Yes, you do not need to leave the browser running only for this file. The only requirement here is that you must have the file download link. The syntax of the command is as follows:
curl -0 download link
First, navigate to the folder where you want to download the file. To do this, you must go to the Downloads directory.
cd ~/Downloads
After that, you can feed the command to download the VLC for macOS from the official website. It seems like 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. Same for backups
Copying files and backing up to macOS is fast enough – thanks to SSDs and flash storage. However, copying a large amount of data takes a long time. Fortunately, Terminal offers a useful command to copy files. Here's how to do it by looking at the name of the files copied by the command.
idem -V / currentpath / / new / path /
I want to copy the downloaded DMG file in the previous section on the desktop.
ditto -V ~/Downloads/vlc-3.0.7.1.dmg ~/Desktop
This should do the right thing. If you want to copy the files to an external drive, you must provide the destination path correctly.
8. Always show the file path in the Finder
If you changed Windows, you would have noticed that the Finder on macOS does not show the file path as the Windows Explorer. However, you can force Finder to show you the file path with this command:
defaults write com.apple.finder _FXShowPosixPathInTitle -boolean true
After pressing Enter, you must stop the Finder.
killall Finder
After pressing Enter, the Finder will be restarted. Then you should see the file paths at the top of the Finder window.
9. Power chime when connecting the charger
Have you ever connected the MagSafe charger to your Mac without forgetting to press the power switch? I lost the account. Fortunately, I came across this useful command that provides an audio chime back when I connect the MagSafe charger.
Load this command into the terminal and press Enter.
defaults write com.apple.PowerChime ChimeOnAllHardware -bool true; open /System/Library/CoreServices/PowerChime.app
10. Stop your Mac from sleeping
Often you download a large file and you do not want your Mac to fall asleep. If it is a temporary requirement, a simple command can get there. Just type the following command, press Enter and exit your Mac.
caffeinate -u -t 600
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 "caffeine"to prevent your Mac from sleeping.
However, if you close the window of this terminal, the command stops the run and the Mac goes to sleep at a predefined time.
11. Check the availability of your Mac
Ever wondered how long you have restarted your Mac? A simple reboot can sort a lot of things and improve the performance of your Mac. Here's a command to check how long your Mac has been running without restarting or shutting down
uptime
This should give you all the details with a timestamp.
Using a terminal, it's fun
The terminal is a pure pleasure to use and tinker in the macOS. However, we strictly advise against using random commands provided by unverified sources or unknowns. Apart from that, these commands must be run on the latest macOS Mojave update until the latest version.
You should always check the device's commands to delete, delete, or disable any service. If you stick to our list, you'd be confident to use Terminal like a pro.
Then: Are you tired of the same old lock screen on your Mac? Here's a handy guide that will show you how to customize the lock screen of your MacOS Mojave on Mac.