14 Useful Mac Commands You Should Start Using Today

14 Useful Mac Commands You Should Start Using Today



I am a GUI person; no matter how long the steps are, I walk through every button to complete the task. In contrast, I have a friend who uses the terminal to navigate and complete almost all tasks, saving a significant amount of time.

The biggest pain points for me are remembering those shortcuts; even if I try, after a couple of days, I go back to the same old pattern. Over the last month, I have decided to use shortcuts again and make them a habit. To achieve this, I created a list of all the useful commands (up to 50) and started using them.

It was not easy at the beginning; however, instead of using all fifty shortcuts, I selected the ten best commands that are most frequently used, can save time, and are easy to remember. So, if you are someone who uses a GUI to navigate and finish tasks and want to save time, or if you are already familiar with commands and looking to learn more, here are the 25 Best, most useful commands and how to use them.

14 Best Useful MacOS Commands

Feature
Command
Open any file
open MyFile.pdf
Open a website
open https://example.com
Open an app
open -a “App Name”
Hide desktop icons
defaults write com.apple.finder CreateDesktop -bool false && killall Finder
Unhide desktop icons
defaults write com.apple.finder CreateDesktop -bool true && killall Finder
Keep Mac awake
caffeinate
Keep awake for x seconds
caffeinate -t 1800
Show only active apps in Dock
defaults write com.apple.dock static-only -bool true && killall Dock
Restore full Dock
defaults write com.apple.dock static-only -bool false && killall Dock
Calendar (month)
cal
Calendar (year)
cal 2025
Find day of a date
date -jf “%Y-%m-%d” “2002-11-05” “+%A”
Test internet speed
networkQuality
Detailed speed test
networkQuality -v
Save speed test
networkQuality -v > ~/Desktop/speedtest.txt
Create password ZIP
zip -er Protected.zip FolderName/
Unzip password ZIP
unzip Protected.zip
Shutdown now
sudo shutdown -h now
Shutdown in 5 min
sudo shutdown -h +5
Restart Mac
sudo shutdown -r now
Cancel shutdown
sudo shutdown -c
Hide file/folder
chflags hidden Path
Unhide file/folder
chflags nohidden Path
Change screenshot format (JPG)
defaults write com.apple.screencapture type JPG && killall SystemUIServer
View battery health
system_profiler SPPowerDataType
Batch rename files (prefix)
for file in *.jpg; do mv “$file” “pic-$file”; done
Kill all processes of an app
pkill -f “Google Drive”

Open Files Quickly

Open any file

I don’t know about your device, but my MacBook takes ages to launch any files, whether it’s opening Finder to open the latest downloaded file or opening Google Chrome to visit our website.

However, with this command, you don’t need to wait longer. You can simply open any file or URL by using this command; the best part is that it is easy to remember, too. Here is how to use it.

  • To open a specific file, use the following command: open MyFile.pdf. Ensure the file name and extension are correct
  • To open any website: open website link
  • To open any app: open -a “app name”

Hide Your Cluttered Desktop

Hide your cluttered desktop

If you are like me, who has a cluttered desktop, then this can be a lifesaver. Whenever you want to share the screen in a meeting or want to take a screenshot of your desktop, you don’t need to arrange files into a folder or move them.

You can simply use this command to hide all files on your desktop, offering a clutter-free experience. Here is how to use

How to hide files

Use this command to hide all the files on your desktop

defaults write com.apple.finder CreateDesktop -bool false && killall Finder

And when you’re finished, you can unhide all the files using this command

defaults write com.apple.finder CreateDesktop -bool true && killall Finder

However, if you want to view files during your presentation, you can go to Open Finder > Go to  and the Desktop folder to view the files

Prevent Your Mac From Sleeping Automatically

Prevent your Mac from sleeping automatically

There are times when you want your Mac to stay awake, especially when you don’t want to interrupt what you’re doing, such as downloading or running an important task.

Most of us follow the most obvious choice by going to settings and manually toggling auto sleep settings; however, in most cases, we forget to turn it off, leaving our Mac awake, which not only drains our battery but also gives access to others.

To avoid this, you can use the following command. You can use this command to prevent Mac from going to sleep forever unless you manually turn it off – caffeinate

However, you can also set a timer on how long your Mac should be awake: caffeinate -t 1800

Show Only Active Apps in Dock

Show Only Active Apps in Dock

The macOS dock is a useful feature that allows you to quickly launch apps, switch between them, and see which apps are active; however, for most users, the dock is often filled with Apple’s default recommendations. In my case, almost 80 percent of my dock is filled with unused Apple services.

Using this simple command, you can see only the active apps currently running in the background, which will help you make your dock less cluttered and more useful. Here is how to use it

To show only active apps :

defaults write com.apple.dock static-only -bool true && killall Dock

To bring back all apps and your default dock

defaults write com.apple.dock static-only -bool false && killall Dock

View Calendar Quickly

View Calendar Quickly

There are times when you occasionally need to open the calendar to find dates and determine the current day. Like any other device, macOS also comes with a built-in calendar app that lets you do all of that; however, if you want the quickest way possible, you can use the terminal to view the calendar and determine the exact date and day using simple commands.

For instance, your friend is getting married next month, and you want to know the exact day to plan in advance. You can simply go to the terminal and enter the date, and it gives you the exact day instantly without opening the calendar. Likewise, you can find any day in the past by giving the date as an input.

Here are all the necessary commands.

To view the current month: cal

To view the whole year’s calendar: cal 2025

To find the day of any date

date -jf “%Y-%m-%d” “2002-11-05” “+%A”

Test Your Internet Speed

Test Your Internet Speed

Lately, fast.com has become the most visited website on my browser, thanks to the frequent fluctuations in internet speed. Like any other online utility tool, you first need to open a browser, navigate to the website, and wait for the tool to load. Then, test your internet connection.

However, with this simple command, you can quickly diagnose your network speeds. The best part is that it is accurate and not influenced by ads or trackers, which can sometimes be inaccurate.

How to test internet speed using this command

To test internet speed: networkQuality

To run a detailed test

networkQuality -v

If you want to save these tests for later reference or want to share them with someone, you can use this command

networkQuality -v > ~/Desktop/speedtest.txt

Create a Password-Protected ZIP

Create a Password-Protected ZIP

Zip format is often the best way to compress files and store them securely on your Mac without occupying a lot of space; however, if you are storing sensitive files, it is often best to protect them with a password.

The best part is that since the zip format is universal, it works on all platforms, including Windows and Linux. Even if someone manages to copy your zip files, they still cannot open them without the password.

Here is how to password-protect your zip files

Go to the folder you want to convert into a zip: you can use this command:

cd ~/Documents

Now use this command:

zip -er Protected.zip FolderName/

Now enter the password and verify it. You will see something like

Enter password:
Verify password:

To unzip later, you can simply use this command

unzip Protected.zip

You can also unzip files by double-clicking on the file and then entering your passcode.

Convert Files Into Custom Ringtones

Convert files into custom ringtones

With iOS 26, Apple has finally added support for setting custom ringtones on iPhone; however, if you are on an older version, you still have to depend on third-party methods to set custom ringtones on your iPhone. However, using this simple method and using command-line tools, you can make that process easy. Here is how

Place the song file on your desktop. And go to the file using this command: ~/Desktop/song.mp3

Now use this command to convert the file into a compatible ringtone format

afconvert ~/Desktop/song.mp3 ~/Desktop/ringtone.m4r -f m4af

Next, you need to trim the files

To do this, you can use this command without relying on media cutters

ffmpeg -i song.mp3 -ss 00:00 -t 00:30 trim.mp3
afconvert trim.mp3 ringtone.m4r -f m4af

That’s it; now you can connect the file to the Finder app or use iTunes to set a new ringtone. It also works for current iPhones; you can simply convert the files, share them with your iPhone and then set it as your custom ringtone.

Shut Down or Restart Using Terminal

Shut down or restart using Terminal

This is one of the most useful commands I use frequently. As the name suggests, you can use the terminal to quickly shut down or restart your system. And it can be a lifesaver when UI freezes, lags, or becomes unresponsive.

Here is how to use command tools to shut down or restart your computer. Not just that, you can also set a timer to automatically shut down your Mac after a certain time. For instance, you can set your Mac to automatically shut down after 5 minutes.

sudo shutdown -h now

Shutdown your Mac after 5 min.

sudo shutdown -h +5

To restart your Mac

sudo shutdown -h +51

To automatically shut down at a specific time :

sudo shutdown -r 22:00

To cancel the shutdown, you can use

sudo shutdown -c

Hide and Unhide Files or Folders

Hide and Unhide Files or Folders

Even after macOS, there is no option to hide and unhide files through Finder; the only method is to use the terminal. Using this command, you can hide any file or folder on your Mac from the Finder.

Remember that this command only hides the folder from the Finder; users can still see it using simple methods and can also if someone searches for the file name or its contents. Here is how you can use it

To hide any file or folder, create a new folder and name it ” secret folder.

Now use this command to hide it:

chflags hidden ~/Desktop/SecretFolder

If you have already created a folder and want to hide it

Open a terminal and use this command.

chflags hidden

Now, use the drag and drop option and drag and drop any folder or files into the terminal
To unhide it

chflags nohidden ~/Desktop/SecretFolder

To view the folder without unhiding it, use this command.

Command + Shift +.

Change Screenshot Image Format

Change Screenshot Image Format

By default, macOS stores screenshots in PNG format. While PNG offers better quality than JPG and is a larger file, it can take a significant amount of storage. Now, using this command, you can change the screenshot image format to JPG or even HEIC if you prefer the Apple method. Here is how

To change screenshots format from PNG to JPG,

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

To change it to HEIC

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

To change it back to PNG

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

While doing so, you can also use this command to change screenshot’s location

defaults write com.apple.screencapture location “~/Pictures/Screenshots” && killall SystemUIServer

Quickly View Your Mac’s Battery Health

Quickly view your Mac’s Battery health

Apple devices are popular for displaying battery health. This helps you determine your current battery health status and when to replace it. However, this command offers more details than just showing your battery health.

You can view it to see how many full charge-discharge cycles your battery has gone through, among other details. It also displays your current status, battery condition, and connected charger information, including the manufacturer’s details and more. You can simply enter this command in the terminal, and you can access all the information in one instance

system_profiler SPPowerDataType

Batch Rename Files

Batch rename files

Managing files in macOS can be one of the toughest tasks; however, with this simple command, you can easily bulk rename all your files.  Here is how it works: you can rename the files, add specific tags, and a prefix to the files to easily identify them.

For instance, if you have saved all recently uploaded product screenshots, you can locate them, rename them according to your desired names, or remove existing names and replace them with new ones. Here is how it works

To add a prefix to the files

for file in *.jpg; do mv “$file” “pic-$file”; done

To add a suffix to the files

for file in *.jpg; do mv “$file” “${file%.jpg}-edited.jpg”; done

Add a copy tag to the duplicate files

for file in *; do cp “$file” “copy-$file”; done

Rename files based on their size

for file in *; do size=$(stat -f%z “$file”); mv “$file” “$( ([[ $size -lt 100000 ]] && echo small) || ([[ $size -lt 500000 ]] && echo mid) || echo big )-$file”; done

Add dates to each file

for file in “Screen Shot *”; do mv “$file” “$(echo “$file” | sed ‘s/Screen Shot //g’)”; done

Kill All Background Processes of a Specific App

Kill all background processes of a specific app

If an app is unresponsive and uses a lot of resources, you can simply force it to stop on your Mac; however, even after forcing it to stop, some background process of the app might still be running in the background. You can resolve the issue using this simple command.

Command: pkill -f “Google Drive”

Before You Go

Those are the fourteen best macOS commands I’m using regularly. Using these commands not only saves time but also makes it easy to manage and use a Mac. To use, copy the commands highlighted in red and paste them into a Mac terminal. If you encounter any issues while using these commands, you can always use this command: defaults delete com.apple.finder; defaults delete com.apple.dock; defaults delete com.apple.screencapture; killall Finder; killall Dock; killall SystemUIServer to reset everything to its default settings. I hope you find this guide helpful.



Source link

Leave a Reply