What is a Terminal on Mac?
Some MacOS users might be intimidated by the Terminal and its commands. When using Terminal on Mac, it might look like you are trying to hack into a system. While of course, it is not the case, knowing Mac Terminal commands will give you an upper hand in mastering the MacOS environment.
As a Terminal emulator, it provides you with text-based access to the operating system. It’s a quicker way of navigating the operating system, provided that you are familiar with the Terminal commands on Mac. Once you grasp its basic functionality you can take on more complex tasks and when you do so, using the Terminal can be a lot of fun.
While you will not be a IT specialist right away by knowing your way around the Terminal, it’s the first step to becoming one - if that’s your goal...
How to open the Terminal on Mac?
The Terminal application is in the Utilities folder in Applications. There are several ways you can access Terminal.
In Finder, navigate to the location of the Terminal application which is:
Applications > Utilities > Terminal
An alternate method is from Spotlight Search. Push command and space buttons together to bring up the Spotlight Search bar. Type in the word Terminal and click on the first suggestion.
Either of these two methods will bring up the Mac command prompt and it will look like a black box as below.
Depending on your Terminal setting, the appearance may look different. First, it’s best if you adjust the appearance to fit you. Changing the theme of the Terminal lets you do just that.
While on Terminal, navigate to ‘Terminal’ on the top bar and select Preferences.
In the preferences menu, navigate to the Profiles tab.
Here, you can customize the appearance of the Terminal including the background color, text color, and font.
Terminal tricks you should know
Navigating the Terminal might not be as straightforward as navigating a GUI application. Therefore it’s important that you learn a few things that you should keep in mind when learning the Terminal.
Use the arrow keys or the mouse to navigate the Terminal. If you want to edit the command you entered, move left or right using the arrow keys until you reach the place where you would like to edit. Another option is to use the mouse—ALT-click to move the cursor to a certain position in the line.
Once you have entered several commands and you would like to enter one of those commands again, you can use up and down arrow keys to navigate through the past commands you have entered until you select the desired command. This way you do not have to type the same command over and over again.(Video) Absolute BEGINNER Guide to the Mac OS Terminal
Terminal commands should be typed exactly as they are shown. Every character, every space, and every symbol matters. Removing any characters will give you an unexpected result.
Once you enter a command, to execute it you need to press the return/enter key. Once you hit the return/enter key, you can interrupt the command by pressing CTRL + C simultaneously. This will stop the command from completing its task.
The commands you run on the Terminal will execute in the current file location. To change the file location, you will use the Terminal command introduced below.
Mac Terminal Commands List
There are tons of commands that you can make use of. Let’s focus on some of the most common MacOS Terminal commands you need to be familiar with when you are mastering the Terminal.
There are a few features that are applicable for any command.
If you do not know what a command does or what a specific parameter related to a command does, the manual (man) page will provide you with all the information you need.
Current Directory. Wherever you are required to enter a directory location, this will refer to the directory you are currently in.
Parent Directory. Wherever you are required to enter a directory location, this will refer to the parent of your current directory
Wildcard. Anything that matches certain criteria. For example “*.jpg” means any file with the jpg extension.
Used to clear the space of your Terminal
Some commands require you to be a superuser. In such cases, you can use this command to gain such privileges provided you are an admin of the system. You will be required to enter your administrator password to execute such commands.
The Terminal keeps a history of all the commands you have entered. This command will display all the commands you have entered.
Deletes the command history of the Terminal
List Directory commands
These commands are the most commonly used set of commands. These are very helpful when you want to list the contents of a folder.
Print working directory (Outputs the address of the current directory )
Displays the names of files and subdirectories containing in the folder
Lists in the long format. Includes information like file mode, owner, group name and many more
Lists detailed directory contents including hidden files.
Change Directory commands
The following commands will let you change the directory that you are currently working in. This is especially useful when selecting the directory you want to run a command in.
Go to Home Directory
cd [folder name]
Change directory (If the directory you would like to navigate to is not in the current directory, the complete file address is required )
Move up to the parent directory
Move up two levels (Could be extended to as many levels as possible by adding ../)
Go to Home Directory
File and Directory management
Let’s look at how you can create, edit, and delete directories and folders.
Create a new subdirectory in the current directory
mkdir <dir1> <dir2> <dir3>
Create several directories at once.
Create a folder with a space in its name
rm -R <dir>
Remove a directory and its contents
cp -R <dir> <”newdir”>
Copy a folder to another folder with spaces in its name
Create a new file
Opens a Terminal file editor. You can make changes to your files right from the Terminal.
cp <file> <dir>
Copy a file to a directory
cp <file> <newfile>
Copy a file to the current directory with the name given as <newfile>
Remove a file completely. This will remove it completely from the system so be careful when using this command.
rm -i <file>
Deleting a file after providing confirmation.
mv <file> <newfile>
Move a file to another file/ Rename a file
mv <file> <dir>
Move a file to a folder and will overwrite existing files
mv *.txt <dir>
Move all text files of the current folder to a different folder
Relevent reading:How to correctly uninstall apps on Mac
Changing permissions of files and folders is important to prevent unauthorized access to the resources. You can provide permissions for reading, writing, and executing to the owner, a group or others.
To view permissions of a file you can use ls -l command that we talked about in the List Directory commands section. This will list all files and folders in the long format. On the left-most column, you will see a notation as below.
rw-r--r-- OR drw-r-xr-x
There are nine slots with three groups for each type of user; owner, groups, and others. In the first example rw-r--r--, the owner has read (r) and write (w) permissions but has no execute (x) permission. Both groups and others only have read (r) permission.
In the second case, drw-r-xr-x, apart from the usual permission sets there is a d which represents that this is a directory.
Before moving on to the commands, you have to be familiar with octal permission notation
Write and Execute
Read and Execute
Read and write
Read, Write and execute
The Terminal application allows you to set octal notation permissions for files and directories. Let’s look at what commands you can use.
View permissions of a file or directory
chmod 500 <file>
Change the permissions of a file to 500 (r-x------)
chmod -R 600 <dir>
Change the permissions of a folder and its contents (drw-------)
chown <user> <file>
Change the owner of the file
chown <user>:<group> <file>
Change both the owner and the group of the file
The Terminal allows you to view the processes that are currently running on your system, examine their resource usage, and kill them. These commands basically act as a replacement for the Activity Monitor GUI application.
Gives you a detailed view of every process that is running in the system. It includes information like the PID (Process ID), elapsed time running, the process name, and location.
ps -ax | grep <application name>
Allows you to view information about a specified application. The pipe symbol (|) takes the output from the first command and provides it as an input to the grep function.
Displays real-time information about the processes that are running on the system
Once you find the PID from the ps -ax command, you can kill the process using this command.
While all the above tasks could be achieved using GUI applications, the easiest and the most convenient way to configure your network and gather information about your network is through the Terminal.
There are several useful Terminal applications that will help you in this regard.
While there are many uses for this command, the most common is to check your IP address
Test whether you can make a connection to the host. The host could be the IP address of a device connected to your network or a web domain
Lists all your current incoming and outgoing connections.
The output is the whois info of the domain. The information includes basic contact details, Name Servers, and much more
View a list of all active devices on your local network. It will show you the IP and MAC addresses of all the devices.
This is an important troubleshooting tool. It traces the path, packets go through. If your connection with the host is not established, you can pinpoint the exact location at which the packets do not pass.
curl -O <url to file>
If you need to download a file from the internet without a browser curl gives you the option to download over HTTP, HTTPS or FTP
Searching through your Mac is easy using the command line using the following commands.
find <dir> -name <file>
Find the file in the specified directory
find . -name “*.jpg”
Find all files with the jpg extension in the current directory.
Determining File Type
Sometimes the extension will not help you in determining the type of file. In that case the following command can help you pinpoint the exact type.
Determines file type
We explored some of the most useful commands available in the Terminal. There are a plethora of commands available to fulfill any task you can think of. While it’s not easy to remember every command in detail, it’s important to be familiar with the most used commands that are mentioned above.
If you are aspiring to become an IT specialist, knowing your way around the Terminal is one of the most basic skills that you would have to acquire. Now that you have grasped the basics of the Terminal, we hope that you will dig deeper and master the most useful tool in your IT toolbox.
Written byShanika Wickramasinghe.
Shanika is a software engineer by profession and a Graduate in Information Technology. Her fortes are Web and Mobile Development. Shanika is a macOS enthusiast and loves writing as it helps to share her knowledge. She also enjoys sharing tips and tricks about macOS. You can connect with her atLinkedIn.
The top command shows a live view in the Terminal with the list of apps with the most CPU utilization. The top command also displays memory, CPU and disk stats at a glance. To close this view, either close the Terminal window or go back to the command line prompt by pressing Control + C to quit the top command.What are the commands for Mac Terminal? ›
|sudo [command]||Run command with the security privileges of the super user|
|nano [file]||Opens the Terminal editor|
|open [file]||Opens a file|
|[command] -h||Get help about a command|
|Move to the next bookmark||Option+Command+Down Arrow|
|Move to the previous bookmark||Option+Command+Up Arrow|
The top command shows a live view in the Terminal with the list of apps with the most CPU utilization. The top command also displays memory, CPU and disk stats at a glance. To close this view, either close the Terminal window or go back to the command line prompt by pressing Control + C to quit the top command.What does command D do in Terminal Mac? ›
|Split window into two panes||Command-D|
|Close split pane||Shift-Command-D|
- Click the Finder icon in your dock to open Finder.
- Navigate to the folder where you want to find hidden files.
- Press Command + Shift + . (the period key). This will show hidden files in the folder.
- To hide the files again, press Command + Shift + . again.
- Open a terminal window. On windows, open a Command Prompt window, on MacOS, open a terminal window.
- Navigate to the folder or file you want to open (using cd) In this case I want to navigate to my desktop to open a folder called "MyProject" cd Desktop.
- Type "code" [path to file]
By typing commands in the Terminal, you can access files, install programs, modify programs, get information about various things (for example, check things like package loss and speed of your internet) and do more or less everything else as well.What does command Alt R do on Mac? ›
If your Intel Mac has a T2 chip you can use this key combination: Option/Alt + Command + R will install the latest macOS on your Mac if you have a T2 chip.What is Ctrl Shift V on a Mac? ›
Command + Shift + V
This is the shortcut for “Paste and Match Style,” which basically means you can copy and paste something without its previous formatting.
Terminal commands are the instructions that you type into the terminal to execute a specific task. Depending on your operating system, you'll run the terminal commands in a specific shell. For Linux, it's most likely Bash, for newer macOS versions it's Zsh, and for Windows it's PowerShell.What is the more command on a Mac? ›
The more command reads files and displays the text one screen at a time. The command pauses after each screen and prints the word More at the bottom of the screen. If you then press a carriage return, the more command displays an additional line.Are macOS Terminal commands the same as Linux? ›
While many Mac terminal commands are similar to Linux commands, macOS also features system-specific syntax designed to help Mac users manage their hardware and software.What does C mean in terminal? ›
In most terminals Ctrl + C (represented by ^C ) are used to halt the execution of a process, hence pasting with that short cut won't work. For quick copying and pasting, you can utilize X's primary buffer by highlighting whatever text you want to copy, and then middle-clicking where you want to paste it.What is Control C in terminal? ›
Ctrl+C in a command line environment
While in a command line such as MS-DOS, Linux, and Unix, Ctrl + C is used to send a SIGINT signal, which cancels or terminates the currently-running program.
Ctrl + Z Pause Processes in Windows Command Line
The shortcut is critical when running a long process. You may want to pause the process to take a closer look without waiting for it to finish. Pressing the Ctrl + Z shortcut in CMD sends the SIGTSTP signal that suspends a running process.
The Z shell, more commonly referred to as zsh , is a UNIX shell that is built on top of the Bourne shell (macOS default shell), better known as bash . Z shell is basically an extended version of Bash, with many additional features. To learn more about the basics of Bash, read: Deck Out Your Mac Terminal: Bash Basics.How do I find my IP address on a Mac Terminal? ›
- For wired connections, enter ipconfig getifaddr en1 into the Terminal and your local IP will appear.
- To see your public IP address in the Mac Terminal, type curl ifconfig.me and your public IP will display.