Terminal Full Guide for Mac | How to Open and Use Terminal on Mac

Lucien updated on Aug 03, 2022 to Knowledge Center

How to open and use the Terminal application on a Mac computer, with some basic commands you can use to control the operating system

We are familiar with the GUIs we use to interact with Macs daily, but not so much with the Mac command line interface - the Terminal. It's beneficial for people who are used to using the command line.

It can be more efficient at handling tasks, troubleshooting issues, and repairing disks via SSH or Mac single-user mode when you lose access to your user account.

Let's start with some basics to help you dig deeper and tackle complex tasks in the future.

How to Open Terminal on Mac

You can access Terminal in two main ways: the Applications folder in Finder or by searching in Spotlight. Here's a quick run of both processes.

Open Terminal via Finder

1. Click on the Finder logo (it looks like a two-tone smiley face) located in the toolbar at the bottom of the screen.
2. On the left toolbar, click Applications (if this is the last folder you accessed in the Finder, the Finder will automatically open that folder).
3. Scroll down and open the Utilities folder.
4. Double-click "Terminal" to launch it.

Open Terminal Mac

Open Terminal via Spotlight

1. Press the Command button and the space bar simultaneously (this will open a search bar on your screen).
2. Type "terminal" (it should auto-populate as you type).

Open Terminal via Spotlight

3. Double-click "Terminal" in the left sidebar to open the Mac's Terminal

If you plan to use Terminal frequently, it's a good idea to dock it to your computer's bottom toolbar ("dock") for easy access. To do this, right-click on the Terminal logo in the Dock (as long as the Terminal is open, it will be there). Then hover over Options and select Keep in Dock.

Learn More: What is HFS+; APFS(Apple File System)

Basic Mac Terminal Commands

This section will explain some common commands that can be used to accomplish simple tasks. If your file system is case sensitive, Terminal will only recognize the original name, so Desktop cannot be the Desktop. When unsure which directory you are in, type PWD to check.

How to kill a process in Terminal?

Force quitting a process will result in all your unsaved changes, so ensure the target process is correct and save your changes. There are two ways to kill a process using Mac Terminal.

Terminate the process immediately:

Kill PID number

If you want to force, quit Music, type top in a terminal window and press Enter. Then find the PID number of Music, and enter q to return. You can now type kill 1234 to quit Music immediately (assuming Music's PID number is 1234).

To kill all processes with a specific name:

kill all process name

If you need to kill all processes with Google, enter killall Google.

Warning: Mac Terminal will not ask you to confirm that you want to kill the process, so use these commands with caution.

If you just want to interrupt a running process in Mac Terminal, you can press Control-C.

How to change the directory in Terminal?

To change directory:

cd ~/desired directory
or   
cd the desired directory

When you open a terminal window, you go to your home directory. If you need to navigate to another folder, you can copy this command to the Terminal and change the "desired directory" for the folder you want to open. For example, to switch to the Desktop, insert cd desktop. Don't forget to press enter after entering the command.

How to List directories in Terminal?

To list directories in Terminal:
ls
After using the cd command to change to the desired directory, you can use ls to view all the files or folders in it.

How to create, open and delete directories in Terminal?

Create a new folder:
mkdir folder name

Create a new file:
touch filename.format

For example, I want to create a folder called test1. Then I would type mkdir test1 and press Enter. Now in this folder, I can type touch sample.txt to generate a txt file called sample.

Open a file in the current folder:
open filename

Open a file in another folder:
open file path

Open an application:
open -a application name

Open a file with the specified application:
open -a application name file path

For example, to open the Music app, you would type Open -a music. If you need to open a file with a specific application, say WPS Office, to open a file named sample.txt, you can use Open -a wpsoffice /Users/jenny/test1/sample.txt. File paths can be easily dragged and dropped into the terminal window.

Delete Files:
rm filename

Delete folder:
rm -r folder name
The files deleted by this code are gone forever, and there is no way to get them back. So be careful!

Copy files from one folder to another:
Ditto Folder 1 Folder 2
Folder 1 contains the files you want to copy, and folder 2 is where you want to paste the files.

How to find IP address on Mac Terminal?

Wired Internet Connection:
ipconfig getifaddr en1

Wi-Fi connection:
ipconfig getifaddr en0
Enter any command to find out your local IP address easily. Do not confuse ipconfig with ifconfig used on Windows.

How to reset a Mac password using Terminal?

Reset Mac password:
reset Password
Boot into recovery mode and type reset password after launching Terminal. You can select the account you want to reset your Mac password and enter a new one.

How to repair disk using Terminal?

Verify the primary disk:
diskutil verify volume /

Repair the main disk:
diskutil repair volume /
Verify an external hard drive, for example, and a drive called a backup. You can enter diskutil verifyvolume /Volumes/backup/ and press Return. If it reports any errors, you can use diskutil repairvolume /Volumes/backup/ to repair the external hard drive on your Mac.

How to quit Mac Terminal?

You can exit your shell session first to avoid interrupting ongoing processes by typing exit and pressing enter. Then on the Dock, you can leave the Terminal by right-clicking the Terminal and selecting Exit.
Learn More:  What is NTFS ;What is USB Flash Drive

Related Articles