Most useful Terminal commands for macOS (2022 Updated)

Most useful Terminal commands for macOS

Terminal is one of the most powerful macOS apps, allowing you to perform actions with different commands. Although Terminal commands may seem intimidating to carry out, they aren’t! Once you know them, you can quickly perform tasks like shutting down your Mac or copying contents from one place to another in a few clicks.

Terminal is a CLI (Command Line Interface), the language we type which interacts with the Mac. This tool is often overlooked as it is different from the GUI (Graphical User Interface), offering a rich interface. However, I’ve a useful list of macOS Terminal Commands that you can learn easily and do things instantly. Let’s start with the basics!

How to open Terminal on Mac

Spotlight is undoubtedly the easiest way to open Terminal on Mac. Follow the steps below to open Terminal.

  1. Tap the magnifying glass icon in the menu bar to open Spotlight.
    Alternatively, you can also press command + spacebar to open Spotlight.
  2. Type Terminal in the Spotlight Search bar.
  3. Press Return.
    Terminal is now open and ready to use.

Now, let’s see how to get most of Terminal!

12 macOS Terminal commands to supercharge your Mac experience

1. Force your Mac to stay awake

It is annoying when your Mac goes to sleep when you are off for a short break. Of course, you can change Sleep Settings in System Preferences. However, it is easier to use Terminal to keep your Mac awake with the following command.


Terminal command to force your Mac to stay awake

That’s not all! You can also add a timer to the command. Doing so will disable “caffeinate” mode after a preset time. You need to put the -t flag and specify the time in seconds, as shown below.

caffeinate -t 150000

In this case, your Mac will exit the mode after 15,000 seconds or 250 minutes. You can increase or decrease the timer by changing the number of seconds in the command.

2. Flush DNS cache

I have seldom faced issues with Mac’s DNS cache. Yet I would suggest you flush DNS cache on Mac every once in a while. Not doing so will lead to problems like loading websites and 404 errors. (add screenshot- macos-shell-flush-dns)

Enter the following command to flush DNS on Mac.

udo dscacheutil -flushcache; sudo killall -HUP mDNSResponder

Note: This command works only on macOS El Capitan and above. After flushing DNS, check if you can access the website with the issue.

Flush DNS cache terminal command for macOS

3. Increase spacing between Dock apps

Too many apps in Dock triggering your OCD? Well, you can increase the spacing between each apps using terminal commands. Once done, your Dock will look neat and tidy.

defaults write persistent-apps -array-add '{tile-data={}; tile-type="spacer-tile";}'

And hit Return.

Once done, type: killall Dock and press Return again.

Increase spacing between Dock apps

4. Change default screenshot name

Mac saves screenshot with date and time as default. The naming convention tends to look unprofessional. Worry not; once again macOS terminal comes to the rescue. You can change the default name for a screenshot using the below command.

defaults write name "New Screen Shot Name"

Now type:

killall SystemUIServer

Change default screenshot name on Mac

5. Change default screenshot format

Now that you have fixed the screenshot naming, how about changing the format? macOS saves a screenshot in the PNG format. Some online portals like immigration require images to be in .jpg format.

Spending time to convert saved images to other formats is not ideal. Instead, you can use the terminal code to change the default image format. Furthermore, you can choose between Jpeg, TIFF, GIF, or even RAW (ideal for post-processing photos.)

defaults write type jpg

Change default screenshot format on Mac

5. Download files without a browser

Want to download a file directly? With Terminal, you can download a file directly from the Internet. This method is useful only if you have a direct download link. Type the following command.

cd ~/Downloads/

Note: If you want to download the contents to any other directory, replace “downloads” with the directory name.

curl -O [URL of file you want to download]

6. Compress and password-protect folders

I recommend password-protecting sensitive data before sharing it with anyone. You can share the password separately with recipients. Using Terminal, you can compress and password-protect the folder. You need to navigate to Desktop and select the folder using the below command.

cd ~/Desktop/

Select the folder

zip -er <output folder> <source folder name>

Swap Output folder with the desired name. Specify the origin in the source folder name. In other words, you need to mention the origin and target file names. Interestingly you can also change the extension of the output file. Simply add an extension (e.g., .pdf) at the end of the above command.

7. Display hidden files and folders

macOS hides critical files. The fail-safe mechanism assures that you don’t delete a system file by mistake. Doing so could crash your Mac. However, the feature becomes a limitation whenever you want to view hidden files on an external drive.

The solution for this is the below Terminal command that lets you view hidden files.

defaults write AppleShowAllFiles -bool TRUE

Now you will get to see all the hidden files.


killall Finder

A word of caution: Don’t delete important system files. Before deleting anything, run a Google search. Use “False” instead of “True” in the above command to hide files again.

8. Access iCloud Drive using Terminal

To access the data from your iCloud Drive, use the following command.

cd ~/Library/Mobile\ Documents/com~apple~CloudDocs/

However, we already have a detailed guide on how you can access, copy, or move data to your iCloud Drive, which you can check out anytime.

9. Shut Down or restart Mac using Terminal.

To shut down your mac with CLI (Command Line Interface) aka Terminal, use.

sudo shutdown -h now

Just as shut down, you can restart your Mac by

sudo shutdown -r now

10. Supercharge Time Machine backup

Whenever you’re updating the Mac to the new version, backups are essential. The easiest way to take a backup is to use Time Machine. But do you know? You can speed up time machine backup using the terminal by this command.

sudo sysctl debug.lowpri_throttle_enabled=1

11. Copy contents from one folder to another

Copying contents from one place to another is fairly easy with Terminal. Type in the following command:

ditto -V ~/original/folder/ ~/new/folder/

Replace original with the current directory and new with the name of the directory to which you want to copy the contents.

12. Make your Mac say anything you want

This is the coolest command that macOS provides. You can make your Mac say anything you want by using the say command followed by the words.


Terminal commands ready reckoner

Impressed with all that you can do with the above Terminal Commands? We have curated and compiled the most useful macOS Terminal commands in the table below. Furthermore, the commands are segregated based on their utility.

Shortcut Commands
Open a new tab
Open a new tab
Open a new windowCMD+N
Move to Next TabControl+Tab
Close specific tabCommand+W
Close windowShift+Command+W
Close everythingOption+Shift+Command+W
Navigation Commands
Scroll to the topCommand+Fn+Left Arrow
Scroll to the bottom of the pageCommand+Fn+Right Arrow
Scroll Page UpCommand+Fn+Up Arrow
Scroll Page DownCommand+Fn+Down Arrow
Terminal Command Shortcuts
New CommandShift+Command+N
Insert at the start of a lineControl + A
Insert at the end of lineControl+E
Delete a letterDelete
Terminal Editing shortcuts
Select AllCMD+A
Paste as plain textOption+Shift+CMD+C
Find nextCMD+G
Unmark BookmarkCMD+U
Add bookmarkShift+Command+M
Move to the next bookmarkOption+Command+Down Arrow
Move to the previous bookmarkOption+Command+Up Arrow
Kill commandCtrl+C
Clear screenCtrl+L
Terminal Directory commands
Move to the top-level directory/
Current directory.
Parent directory..
Home directory~ (Tilde)
Open a fileopen [file]
Open help manual for a commandman [command]
Open Terminal Editornano [file]
Move to the home directorycd
Change directorycd [folder]
Show current directorypwd
Move to the parent directorycd..
Move to the root of the drivecd/
Directory File Management
Create new foldermkdir <dir>
Create multiple foldermkdir <dir1> <dir2> <dir3>
Create sub foldermkdir -p <dir>/<dir>
Delete an empty folderrmdir <dir>
Delete Folder with contentrm -R <dir>
Create a new filetouch <file>
Copy a file the folder and rename itcp <file>~/<dir>/<newfile>
Copy a file to the foldercp <file> <dir>
Copy a file to the open foldercp <file> <newfile>
Copy multiple files to a foldercp <file1> <file2> <file3>/Users/<dir>
Delete a filerm <file>
Select and delete multiple filesrm <file1> <file2> <file3>
Rename filemv <file> <newfilename>
Move file to a particular foldermv <file> <newfilename>
Move specific file extensions from one folder to anothermv *.png ~/<dir>
Disk management commands
Check free disk spacedf -h
List subdirectory memory usagedu
Check storage for specific filedu -s
Network commands
Ping hostping <host>
Fetch whois information for a domainwhois <domain>
Download filecurl -O <url/to/file>
Check your IP and MAC addressifconfig en0
Initiate SSH connection to a host with <username>ssh <username>@<host>
Find routes and measure transit delay of packets.traceroute [hostname]
Processes Commands
Show all running processesps -ax
Display live process statisticstop
Display processes with the highest memory usagetop -o rsize
Kill processes using PIDkill PID
Search process using name/PIDps -ax | grep <appname>

That’s it!

These were some of the most common and useful Terminal commands. I hope this helped speed up your work and become a pro Mac user.

Additionally, if you are looking for some quick shortcuts to increase your productivity, check out our ebook on 200+ Mac keyboard shortcuts.

Related Reads:

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.