Written byJenny Zeng
A Complete Guide to Open and Use Terminal on Mac
Summary: This post is a beginner's guide to Terminal, the Command Prompt on Mac. Everything you need to know is covered, including how to open and use Terminal on Mac and a list of some commonly-used commands.
We are all familiar with the graphical user interface that we use daily to interact with our Macs, but not so much with the Mac command-line interface - Terminal. It's the macOS version of Windows's Command Prompt and is very helpful for people who are used to command lines.
It has the advantages of being more efficient with tasks, troubleshooting issues, and repairing disks through SSH or Mac Single User Mode when you lost access to the user account.
Let's start with some basics to help you dig deeper and work with complicated tasks in the future.
Table of Contents:
- 1. What is Terminal on Mac?
- 2. How to open Terminal on Mac?
- 3. How to use Terminal on Mac?
- 4. Basic Mac Terminal Commands
- 5. How to quit Mac Terminal?
- 6. FAQ about Mac Terminal
What is Terminal on Mac?
Generally speaking, people use two interfaces to communicate with computers: GUI (graphic user interface) and CLI (command-line interface).
The Terminal app provides a command-line interface on Mac computers to allow you to control the operating system quickly and efficiently to perform tasks a graphical user interface is unable or requires more effort to deliver.
How to open Terminal on Mac?
If your Mac works well, you can launch Terminal from Desktop through Spotlight or Finder. Otherwise, you can access it from the macOS Recovery mode.
How to open Terminal from Desktop?
The easiest way to open Terminal is from Spotlight search. Click on the small magnifying glass icon at the top-right corner of your Mac or press Command + Space keys at the same time to launch Spotlight. Then you can type in "Terminal" and double-click the appeared Terminal. app to open it.
You can also find it in the Utilities folder under Applications in Finder.
If you plan to use Terminal often, you can pin it on the Dock by right-clicking on the Terminal icon and choosing "Keep in Dock" from the Options menu. If you prefer to open Terminal on Mac with a keyboard only, you need to create a shortcut.
How to open Terminal from macOS Recovery mode?
To launch Terminal on an Intel-based Mac, you need to boot your Mac into macOS Recovery mode by holding down Command + R keys until you see the startup screen at restarting.
For M1 Macs, you need to shut down the computer first and press the power button until you see "Loading startup options", then click Option > Continue. Upon the macOS recovery window, you can pull down the Utilities menu and click on Terminal to open the Terminal app.
How to use Terminal on Mac?
Once you open Terminal, you will see a small window with the title listing the name of the current directory, the type of the shell, and the window's size in pixels. A command consists of three parts: the command name, a modifier to the command's output, and where the command will operate.
- Commands won't execute until you press the return key. If you mistake the code, you may receive an error message, or the command will run in the wrong way.
- You can use the up arrow key to repeat a command. If you want to clear a window occupied with texts, simply type in clear and press Return.
- You usually need to go to Finder to see the changes you made with Terminal, except the command requires a new window display.
Basic Mac Terminal Commands
We will explain some common commands you can use to finish simple tasks in this section. If your file system is case-sensitive, Terminal can only recognize the original name, so Desktop can't be desktop. When you are unsure which directory you are in, enter pwd to make a check.
How to kill a process in Terminal?
Forcing a process to quit will cause you all the unsaved changes, so ensure that the target process is the correct one and save the changes you made. There are two ways to kill a process with Mac Terminal.
To terminate a process immediately: kill PID number
If you want to force quit Music, type top in the Terminal window and press Enter. Then find the PID number of Music and type q to return. You can now enter kill 1234 to exit Music immediately (suppose the PID number of Music is 1234).
To kill all the processes with the specific name: killall process name
If you need to terminate all processes with Google, input killall Google.
Warning: Mac Terminal won't ask you to confirm if you really want to kill a process, so use these commands sparingly.
If you simply want to interrupt a running process in Mac Terminal, you can press Control-C.
How to change directory in Terminal?
To change directory:
cd ~/desired directoryor
cd desired directory
By default, you are brought to the home directory when you open a Terminal window. If you need to navigate to another folder, you can use the cd command in the Mac Terminal along with the "desired directory" you want to open. E.g. switching to Desktop, insert cd desktop. Don't forget to press Return after inputting the command.
How to list a directory in Terminal?
To list a directory in Terminal:ls
After using the cd command to switch to the desired directory, you can utilize ls to view all the files or folders inside it.
How to create, open and delete a directory in Terminal?
Create a new folder:mkdir folder name
Create a new file:touch filename.format
For instance, I want to create a folder named test1. I will then put in mkdir test1 and press Enter. Now inside this folder, I can enter touch sample.txt to generate a txt file called sample.
Open a file under 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 a specified app: Open -a app name file path
For example, to open the Music app, you can enter Open -a music. If you need to open a file with a specified app, let's say open a file called sample.txt with WPS Office, you can use Open -a wpsoffice /Users/jenny/test1/sample.txt. The file path can be easily dragged and dropped to the Terminal window.
Delete a file:rm filename
Delete a folder:rm -r folder name
Files deleted by this Mac delete command line are gone forever, and there is no way to get them back. So be cautious!
Copy files from one folder to another: ditto folder 1 folder 2
Folder 1 contains 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 either one of the commands to find out your local IP address easily. Don't confuse ipconfig with the ifconfig used on Windows.
How to reset Mac password with Terminal?
Reset Mac password:resetpassword
Boot into Recovery mode, and type resetpassword after launching Terminal. You can then choose the account that you want to reset the Mac password and enter the new password.
How to repair disks using Terminal?
Verify the main disk:diskutil verifyvolume /
Repair the main disk:diskutil repairvolume /
To verify an external hard drive, for example, one called backup. You can enter diskutil verifyvolume /Volumes/backup/ and press Return. If it reports any error, you can use diskutil repairvolume /Volumes/backup/ to repair the external hard drive on Mac.
If you want to rename files or folders in Terminal, continue reading this article: How to Rename a File or Multiple Files in macOS Terminal?
If you need to check or clear Terminal history, check out this article: How to Check & Clear Terminal History on Mac? (Zsh/Bash)
How to quit Mac Terminal?
You can quit a shell session first to avoid interrupting any ongoing process by typing in exit and pressing the enter key. Then on the Dock, you can quit Terminal by right-clicking on it and choosing Quit.
FAQ about Mac Terminal
There are different types of shells people use to communicate with computers. Bash is one of them, as well as the more recent zsh (z-shell). Bash was the default shell in Macs before macOS 10.15 Catalina, and since then, it is replaced by zsh.
For Macs using the zsh shell, you will see the % sign in the command prompt; and the $ sign is for the dash shell. If you are running macOS 10.15 Catalina and later, zsh is the default shell. Otherwise, it's dash. It's a command prompt that indicates where typing starts.
It is safe to use Mac Terminal as long as you are cautious about using the right commands. The only concern is that a wrong command may cause a lot of trouble since Mac Terminal is powerful enough to have deep access to the system files on your Mac.