The macOS is a UNIX-based operating system. Mac Terminal makes it possible to control the system with a command-line interface. The average user should have no reason to use Terminal. However, if you want to know some neat little tricks, shortcuts, and have the power to tweak almost everything on your computer, you need to know Mac Terminal commands.

When you use Terminal commands for Mac, be sure that you understand what you’re typing. The scripts you enter are powerful and if you’ve made a change you didn’t want to, it can be an inconvenience when you have to figure out what went wrong and go back to revert the change.

If you’re really interested in getting more out of Terminal, you can learn to do more with time as you create your own scripts and customize your Mac according to your needs. However, most users don’t need to go to the advanced level and can still enjoy using their Mac.

Terminal on Mac?

Before we look into some commands on Mac that will make your life easier, let us understand a little more about Terminal.

Mac Terminal is an application you can find in the Utilities folder in Applications. You can launch it like you launch other applications. It is a UNIX command-line environment also known as a shell. There are different types of shell and the one on Mac is called Bash.

When you launch Terminal, you will see the name of the current user, shell type, and window size in pixels on the title bar. Inside the window, the command line starts with the name of the Mac and the current user. You will see a blinking cursor indicating the location where your command will be entered.

How to use Terminal Commands on Mac

1. Man

Mac Terminal allows you to see manual pages or man pages through a command called a pager. The pager command allows you to view content in Terminal. However, you cannot see the entire page at once and have to scroll down to see more content.

You can use the less command to navigate the page. Press Return to move the page down one line. Press the spacebar to scroll one page down.

Type man rsync in Terminal and press Return. The rsync command’s man page is long and you need to use the spacebar several times to reach the end of the document.

If Terminal settings allow, you can scroll up the document. If not, you can use Control+B to go back one page and use Control+F or the spacebar to go one page forward. Press "Q" to close man page.

2. Diskutil

If you want to manage the drives in your Mac, instead of going to Disk Utility, you can use the diskutil command. Using a simple command to format and erase disks is more convenient than following a few steps and using Disk Utility to complete the process.

Using diskutil command is simple. You can just enter the command and press Return key for Mac to list all the functions that can be performed with the command.

You can list disks, mount, format, unmount, and erase using simple commands. You will realize how easy these Mac Terminal commands make your tasks.

Diskutil list List the partitions of disk
Diskutil eject Eject a disk
Diskutil mount Mount a single volume
Diskutil mountDisk Mount a Disk
Diskutil Info Get information a Disk

3. Navigate Files and Folders

You can navigate through files and folders with a few handy commands on Terminal. Use the ls command to see what’s in a folder. It will list all the folders and files in the current directory. Type ls and press the Return key to execute the command.

To access other folders and directories, use the cd command. You initially start in the Home folder. To navigate to the Downloads folder, type cd ./Downloads and press the Return key.

ls list all the files and folders
cd go back to the directory you were in before
cd ./Desktop go to your Desktop
pwd to know the name of the current directory you’re in
clear clear terminal screen
open open files and folders

4. Copy, Cut and Create a Folder

You can use the mv command to move files and folders from one location to another on your Mac. To cut and move a file from your Downloads folder to your Documents folder, enter the following command:

mv ~/Downloads/MyFile.txt ~/Documents/MyFile.txt

To copy and move a file from your Downloads folder to your Documents folder, enter the following command:

cp ~/Downloads/MyFile.txt ~/Documents/MyFile.txt

Use the mkdir command to make a directory on Mac. If you want to create a new folder called fun, enter the following command:

mkdir fun

5. Sync File

You will use the rsync command to synchronize files. To begin rsync, launch Terminal and enter the following command. Your command should look like this:

rsync -r "source folder" "destination folder"

Open Finder and drag and drop a folder to get the source location in Terminal window. Now, drag and drop the destination folder in Terminal window.

6. Working with Disk Image

The hdutil command is for working with disk images. You can create a disk image, mount and unmount a disk image, burn an ISO to CD, and create an encrypted disk image.

To create a disk image from a folder, enter the command below:

hdiutil create test.dmg -srcfolder /path/to/folder/

To mount a disk image, enter the command below:

hdiutil mount test.dmg

To create an encrypted disk, enter the command below:

hdiutil create -encryption -size 25m -volname data test.dmg -fs HFS+J

The command above will create a 25 MB encrypted disk image that is internally formatted as a journaled HFS+ file system.

7. Identify Network

You can easily test your network configuration from Terminal. Use the networksetup command to find information about your computer name, Wi-Fi network, IP address, and more. Use the ipconfig command for a list of commands to view your current network IP address and current network DNS server.

ifconfig view and modify your network settings.
ping test whether you can connect with another network device.
netstat list all incoming and outgoing network connections.

8. Hidden Files

You can either find hidden files on Mac with Finder or use the Terminal app. Follow the steps below to find hidden files with Terminal,

defaults write com.apple.Finder AppleShowAllFiles true
killall Finder

You will see all the hidden and temporary files saved on the desktop when both the lines of code are executed. If you want to hide the files again, replace the value true with false.

If you want to hide file and folder, use this command:

hide file and folder

chflags hidden /path/to/folder/

show file and folder

chflags nohidden /path/to/folder/

Mac Terminal commands are handy and make life easier when you have something quick to check or configure on your Mac. By simply launching Terminal and entering commands on Mac, you can accomplish tasks that take time to complete with regular navigation. There are many more commands other than the 9 Terminal commands we have seen above. If you’re interested in learning more, you can find a task that you regularly perform on your Mac that takes a lot of time and find ways to speed it up with Terminal commands for Mac.