How to Use Terminal on Mac: The Ultimate User Guide

Owners of Apple devices often disregard Terminal as something difficult to master. But actually, there's no need to be an advanced MacBook or iMac user to reap the benefits of this OS X command line. Like any other UNIX-based system, macOS comes packed with the Terminal app that works off a text editor interface. Users have to open the Terminal window and type the commands in, which may seem confusing after operating the cool graphical user interface (GUI) of macOS. Where is Terminal located on a Mac? How to access and use the command-line interface? Learn the best basic and advanced Mac terminal tricks & tips from this tutorial to boost your Mac user experience.

How to Use Command Prompt on Mac?

Using the command prompt can be fun. Before learning a few cool things to do in the Terminal, you need to know where to find it on your Mac. Accessing the Terminal is possible in two ways:

Way #1:

  1. Open the Applications folder -> go to the Utilities folder.
  2. Launch the Add the Terminal icon to your Dock for fast access.

Way #2:

  1. To launch Terminal via Spotlight, type in ‘Terminal’ in the Spotlight search bar.

terminal commands

It is important to clarify a few related terms:

  • Terminal is an emulator serving as the actual interface of the system console. It has no graphical user interface (GUI) and operates as a text editor.
  • System console is the environment that processes and executes the typed-in commands. It includes both the command line and the output from previously executed commands.
  • Command line is the actual line in a console to type the command in.
  • Command prompt is a sequence of characters used in Terminal to indicate readiness to accept commands. In macOS, a prompt typically ends with $ symbol and provides the contextual information like the path of the current working directory and the hostname.

Terminal commands consist of three elements: the program, the option, and the argument. Without going into details, view the next commands before proceeding with this tutorial:

  • ls - list the contents of a specific directory;
  • cd - change to another directory (as in DOS);
  • sudo - authorize as a superuser with security privileges.

Note: The sudo command provides root user privileges, so be careful using it. To execute this command, your OS will require the admin password.

How to Operate Mac Command Line?

Mac commands are powerful tools that can make a user’s life easier. To understand how the parts of a command correlate, view the below example.

  • $ ls

The ls command (short for “list”) is the actual program to display the list of files in a particular Mac directory. To modify the way a program runs, you need to enter an option. For example, -l (short for “long”). The –l option displays the files supplied with detailed information. If the option is missing, the ls command will list the files contained in the current working directory. The command options are not obligatory. When options are missing, commands have certain default behavior.

In this example, the ~ (tilde sign) is the relevant argument. The tilde relates to the objects the ls command is executed on. Here, ~ is a shorthand name for your home folder. Altogether, the sequence ls –l ~ interprets as ‘list all of the files in the home folder.’ Some commands do not require arguments. Depending on the command, arguments may vary, but the order of the arguments is important. To abort the executed command, press Control-C.

Mac users can utilize the cd command to change the current working directory. To specify the directory, add a relevant argument. If the argument is missing, the command lands into home directory (~) by default.

The Terminal environment has a manual for learning specific commands. To access it, type in man and use the name of the needed command as its only argument. For instance, to learn more about ls, run man ls command.

Look up the following useful commands in the manual:

  • mkdir - to create a new directory;
  • touch - to create a new empty file;
  • cp - to make a file copy;
  • mv - to move a file;
  • rm - to remove a file or directory (check the -r option).

Operate Mac

How to Use a Terminal Shortcut on Mac?

Mastering the Terminal is impossible without learning a few useful hacks. Terminal shortcuts are keyboard combinations, or codes used within the Terminal environment to work faster. These key combinations belong to four categories:

  1. Shortcuts to operate Terminal windows and tabs
    • Command-N opens a new Terminal window;
    • Command-T creates a new tab;
    • Shift-Command-N activates the possibility to enter new command;
    • Command-D splits the Terminal window into two panes;
    • Option-Shift-Command-W closes all tabs and windows.
  1. Shortcuts to select, search, and edit text in Terminal
    • Command-C/Command-V to copy/paste text into the Terminal window;
    • Command-X to cut the selected word;
    • Command-F to find the needed text;
    • Double-click on a word to select it;
    • Shift-Command-Double-click to choose a URL.
  1. Shortcuts to operate Terminal marks and bookmarks

Marks apply to a particular Terminal window and execute specific commands within it. They “mark” the positions to return to later on. Bookmarks transcend from one Terminal window/tab to another one. Neither marks nor bookmarks last when you quit the Terminal.

  • Command-U to create a mark;
  • Option-Command-U to create a bookmark;
  • Shift-Command-U to unmark;
  • Command-K to clear and start over;
  • Command-Return to mark a line and send the return.
  1. Oher useful Terminal shortcuts
    • Control-Command-F to launch/quit the full-screen mode;
    • Command-Comma (,) to access Terminal preferences;
    • Command-Double-click the URL to open a link;
    • Option-Command-R to soft-reset the Terminal;
    • Command-S to export text.

Speaking of the Terminal shortcuts, there is a possibility to assign a particular key combination to launch Terminal fast. Please mind that this is a time-consuming process, which requires skill and effort.

What is Mac Console? is a log viewer included with macOS. With its help, users can extract system and application logs, status messages, and activities data to troubleshoot Mac issues. The Console app is handy when no other options are available to fix your Mac. To launch Console, go to Applications -> Utilities. Choose All Messages in the toolbar. It is possible to filter the messages by Errors and Faults to locate the line relevant to your problem. If you already know which app is causing the problem, you can use the search bar to look for the messages related to it. The Console displays an error code that users can Google to solve a problem on their own.

Despite being quite useful, the Mac Console has one serious pitfall. It only shows the data accurate at the time you open the application. Therefore, if your Mac crashed, opening the Console afterward won’t provide any useful information. Users can look through Console's log archives. However, this tedious process requires making a system diagnostic report first.

How to Use Sudo Command on Mac?

Sudo is a Terminal command that allows running programs with a root user privileges. Very often, a root user (superuser) is mistaken for an administrator, so it is necessary to make a distinction between them.

  • The root user is an all-mighty account with full access to all system areas, irrespective of the permissions granted. By default, the root is disabled or hidden, because making changes by mistake can cause irreversible system damage.
  • The administrator is the type of account that allows making system-wide changes but requires authentication to enable access. The sudo command temporarily promotes the administrator to the root user by granting specific read and write permissions.

In comparison, standard and managed user accounts have no exclusive privileges to make system-wide changes or sidestep access limitations.

To execute a sudo command, a user needs to type in the administrator password. A wrong or blank password will prevent the command from execution. In case your administrator account has no password, it is possible to set it in ‘Users & Groups’ preferences. Please mind that Terminal doesn't display the typed-in password. If you make a mistake, the Terminal will request the password again.

mac command

How to Find File in Mac Terminal?

It is possible to search for files on your Mac using special Terminal commands.

  • The find command walks through a specified folder hierarchy to search for files matching a particular name pattern. It is possible to narrow down the search results using command options. To use the find command, specify the starting path and the file name. For instance, the path to retrieve the file called “test.txt” starts in the Users directory: find /Users -name "txt"

When looking for a file, the find command enters any folder in the specified path. The folder may require a user access permission if it has restricted privileges. Often, the find command takes a long time to complete. If only the root folder is specified, it may recourse and never finish the search process.

Two other commands are offering indexed search results:

  • The locate command creates a database of system resources. After that, a user can locate a file by typing in locate Here, NAME is a file name, and the command will show the full path to any file that includes this name.
  • The mdfind command can discover the files indexed with Spotlight on your system. It searches for both user and system files, as well as it locates the items by file name and content. To run the command, type in mdfind NAME.

Can Mac Open Folder in Terminal?

It is possible to open the present working directory in Finder using the open . command in Terminal. As long as you’re located in a local path, you can open any type of system or user files, and launch them into the Finder. This can come in handy if a user needs to find and edit buried system files discovered through the command line. For instance, you are digging around /etc/, the directory containing configuration files for all the programs. If you want to open that directory in Finder, just type in open . to access it.

The Bottom Line is a powerful instrument providing access to features that lie beyond Mac’s standard graphical interface. The command-line interface offers an array of options that are safe to use for Mac users with little experience. However, Mac power users can access the hidden features through the Terminal to make necessary system-wide changes. Using Terminal commands will help you get the most of your Mac!