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.
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.
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.
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.
man [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.
clear
Used to clear the space of your Terminal
sudo [command]
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.
history
The Terminal keeps a history of all the commands you have entered. This command will display all the commands you have entered.
history -c
Deletes the command history of the Terminal
These commands are the most commonly used set of commands. These are very helpful when you want to list the contents of a folder.
pwd
Print working directory (Outputs the address of the current directory )
ls
Displays the names of files and subdirectories containing in the folder
ls -l
Lists in the long format. Includes information like file mode, owner, group name and many more
ls -al
Lists detailed directory contents including hidden files.
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.
cd
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 )
cd ..
Move up to the parent directory
cd ../..
Move up two levels (Could be extended to as many levels as possible by adding ../)
cd ~
Go to Home Directory
Let’s look at how you can create, edit, and delete directories and folders.
Create a new subdirectory in the current directory
Create several directories at once.
mkdir “”
Create a folder with a space in its name
Remove a directory and its contents
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.
Copy a file to a directory
Copy a file to the current directory with the name given as
Remove a file completely. This will remove it completely from the system so be careful when using this command.
Deleting a file after providing confirmation.
Move a file to another file/ Rename a file
Move a file to a folder and will overwrite existing files
Move all text files of the current folder to a different folder
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