Apple’s macOS platform includes Terminal, which is the equivalent of the Command Prompt in the Windows operating system. Because macOS is UNIX-based, Terminal can feel like a dangerous tool where one wrong command can break your system. Sure, but only to a certain extent. There are a number of harmless commands that can be used to customize the interface and other settings of macOS.
Terminal in macOS can be extremely useful in tuning your Mac’s performance. Now it all depends on what you want to achieve. If you’re afraid to use it, you can always relax using simpler tricks. Here are the 11 best terminal command tricks you can try on your Mac.
Note:
1. Open Folders
One of the coolest ways to get to know Terminal is to use it to open files and folders. I know that clicking Finder will do the same. But using Terminal, you can open a specific folder or file without revealing your file structure to anyone.
Let’s say you want to open your Documents folder. Then you can type the following command and press Enter.
Open ~/Documents
And that opens my Documents folder. There is a DOCX file there. I can also use Terminal to open this. For this, you need to type the command with some requirements – path to the corresponding file:
Open -a “Application Name” /Path/to/File
So I typed the following command to open the DOCX file in my Mac’s Documents folder and then hit 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 character (*.extension) instead of the full filename. However, if you have multiple files with the same extension, it can freeze your Mac a bit.
2. Change Default Save Screenshot Location
By default, macOS Mojave stores screenshots on the Mac’s desktop. Now, if you have iCloud sync enabled, which I’m sure you do, then it keeps getting uploaded to your account. Fortunately, you can change the save location for screenshots instead of crowding your desktop.
The command you need to type before hitting enter is:
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 have to reset SystemUIServer for the changes to take effect immediately. So feed the below command.
killall SystemUIServer
Although not necessary, I recommend restarting your Mac.
3. Change Screenshot Type
MacOS saves screenshots in JPG format by default. You can also change them to save in PNG or PDF formats. Here’s how to do it quickly with this particular command:
defaults write com.apple.screencapture type PNG
killall SystemUIServer
Now your new screenshots will be saved in PNG format. Note that PNG files are usually larger than JPG files. So be careful how much storage they consume.
4. Show Hidden Files
Have you tried looking for the option to allow Finder to show hidden files? It’s harder than showing hidden files in Windows. I always forget how to enable it. Fortunately, there is a helpful command that makes it happen in a matter of seconds.
defaults write com.apple.finder AppleShowAllFiles -bool TRUE
After that, you need to force close Finder.
killall Finder
You should now see many hidden files in Finder. They are grayed out but still visible. If you undo this change, you must change TRUE to FALSE in the command.
5. Close Dashboard
Apple introduced the Dashboard view to quickly access the calculator and sticky notes. I bet you rarely use it because you can launch the Calculator app or Sticky Notes app using Spotlight’s Mission Control. So you can turn it off and not have to worry about accidentally opening it.
Here is the command to turn off the Dashboard.
defaults write com.apple.dashboard mcx-disabled -boolean TRUE
Then you must kill the Dock for the changes to be applied properly.
killall Dock
I no longer have to worry about accidentally opening the Dashboard. If you want to turn it back on, change TRUE to FALSE in the command.
6. Download Files
Did you know that you can download files using Terminal? Yes, you don’t need to keep the browser running just for that file. The only requirement here is that you have the download link of the file. So the command syntax is:
curl -0 download link
First go to the folder where you want to download the file. For this you need to switch to the Downloads directory.
cd ~/Downloads
After that, you can feed the command to download VLC for macOS from the official site. It will look something like this:
curl -O https://get.videolan.org/vlc/3.0.7.1/macosx/vlc-3.0.7.1.dmg
Note:
7. Ditto for Backups
Copying files and backing up on macOS is pretty quick thanks to SSDs and flash storage. However, it takes some time to copy large amounts of data. Fortunately, Terminal offers a handy command for copying files. Here’s how you can do this while watching the name of the files that the command copies.
ditto -V /currentpath/ /new/path/
So I want to copy the DMG I downloaded in the previous section to the desktop.
ditto -V ~/Downloads/vlc-3.0.7.1.dmg ~/Desktop
This should do what it takes. If you want to copy the files to an external drive, you must provide the target path correctly.
8. Always Show File Path in Finder
If you’ve recently migrated from Windows, you may have noticed that the Finder on macOS doesn’t show the file path like Explorer on Windows. However, you can force Finder to show you the file path with this command:
defaults write com.apple.finder _FXShowPosixPathInTitle -boolean true
You need to stop Finder after pressing Enter.
killall Finder
After pressing Enter, Finder will restart. Next, you should see the file paths at the top of the Finder window.
9. Power Bell on Connecting Charger
Have you ever connected the MagSafe charger to your Mac but forgot to turn on the power button? I lost the number. Luckily, I came across this handy command that provides an audible feedback chime every time I connect the MagSafe charger.
Feed this command in Terminal and press Enter.
defaults write com.apple.PowerChime ChimeOnAllHardware -bool true; open /System/Library/CoreServices/PowerChime.app
10. Stop Your Mac From Sleeping
You’re usually downloading a large file and don’t want your Mac to go to sleep. If it’s a temporary requirement, a simple command can make it happen. Just type the following command, hit Enter and go away from your Mac.
caffeinate -u -t 600
In this command, the number 600 refers to the second. So with this command the Mac won’t sleep for up to 10 minutes (600 seconds). You can enter a relevant number of seconds or just the word “.caffeineTo prevent your Mac from sleeping.
However, if you close that Terminal window, the command stops executing and the Mac goes to sleep at a predefined time.
11. Check Your Mac Uptime
Wondering how long it’s been since you restarted your Mac? A simple reboot can put many things in order and boost your Mac’s performance. Here is a command to check how long your Mac has been running without a Restart or Shutdown
uptime
This should give you all the details with a timestamp.
Using the Terminal is Fun
Terminal is an absolute pleasure to use and fiddle with on macOS. However, we strongly recommend against using random commands provided by unverified sources or strangers. Other than that, these commands should work in the latest macOS Mojave update until the last few versions.
You should always double check Terminal commands that involve uninstalling, deleting or disabling any service. If you stick with our list, you’re sure to use Terminal like a pro.
Next: Tired of the same old Lock Screen on your Mac? Here’s a nifty guide on how to customize the lock screen on your macOS Mojave running a Mac.