Your complete Mac Terminal Tutorial
The Terminal application on a Mac is a command line interface that allows you to use Unix commands to complete several tasks faster than you can do using a graphical user interface (GUI). Using Terminal commands, you can open files, improve your Mac’s performance, and more. Here’s how to use Terminal on a Mac, including some commands to get you started.
Start By Opening the Terminal
Of course, your first step is to open the Terminal. There are several options for doing that, but the easiest is to press Command + Spacebar to open Spotlight, then search for “Terminal.” The Top Hit must be the Terminal application. Double click to open it.
When the Terminal window opens, you can change its size by dragging one of the corners to expand. You can also change the appearance of the application by opening Terminal> Preferences or pressing the keyboard combination Command +, (comma). In the Profile dialog box that appears, you can change the appearance of the command window to suit your style or needs.
After your Terminal window has the look you like, then you can start using it to run commands on the computer.
Terminal Command Basics
You can do lots of cool (and useful) things with the terminal. For example, if you really want to, you can use the Terminal command to make your Mac talk to you. But before you begin, it’s good to know how Terminal commands are written.
Each Terminal command has three parts.
- Commands: These are the actual letters that you will type in the Terminal window to run commands. Be careful when using Terminal commands, because some commands can delete files or cause other damage to your system that can stop your computer from functioning.
- Argument: This part of the command tells which resources the command should do. For example, should the cp command, or copy, copy this window or something else?
- Options that change output: This is a directive about where the results of certain commands will appear.
For example, if you want to move a file, you will use the mv command. The argument for that command is the location of the file that you want to move. And the result is the location of the file that you want. So to move files from your desktop to your Docs file it might look like this:
mv ~/Desktop/TerminalTestFile.rtf ~/Documents
The command says, “Move the TerminalTestFile.rtf (argument) file from my Desktop to my Document (output).”
In Terminal the tilde character ~ is a shortcut for your Home folder. The desktop and the Documents folder are in the Home folder.
Rules for Using Terminal Commands
Now that you understand the basics of how to write and use Terminal commands, there are some rules that you need to understand.
- When using a terminal, you must always type the command and then press Enter or Return on your keyboard.
- You cannot use the mouse to interact with the Terminal window other than using the Close, Expand, and Hide buttons in the upper left corner of the window.
- To stop a running command type Control + C.
- To exit Terminal without using your mouse, type Command + Q.
- The command automatically runs at the location that was last used on your computer. If you want to specify a different location to execute the command, you must use the cd command and the directory path to determine the location you want to execute the command.
An alternative way to change directories that is very useful if you don’t know the exact directory path, is to use the GUI to navigate to the location you want to include and then drag and drop the directory into the Terminal window. It will not move a directory, instead, it will copy the path to the directory into the command you wrote.
One more note before continuing. If you have never used a terminal before you might get confused when you run a command and nothing happens in the Terminal window. Don’t worry In many cases, that should be the case.
For example, when you type cd ~ you will return to the Home directory. In your Terminal window, your cursor will advance to the next line without any indication that something happened. Rest assured, you are now back in your Home directory.
Use Terminal Commands on Mac
With the basics out of the way, you can start using Terminal commands to move faster and more efficiently because you are using your computer. Here are some Terminal commands that you can try to get your feet wet, but there are dozens of Terminal Mac commands that you can use to fulfill almost all your needs.
Syntactic problem! Make sure when using the Terminal Mac command that you write it exactly as it appears here or in another list. Capitalization and even spaces and punctuation are specific and changing one element can completely change the results of the command.
Most basic Terminal commands involve navigating files or directories on your computer. For example, you can use the ls command (it’s lowercase L, lowercase S) to see a list of all files in the current directory. So, if you are in Documents and you type ls, you will see a list of all files in the Documents directory (or folder).
You can modify (or change the output) of the ls command by adding an operator. For example, ls -C sorts files in the requested list by size.
Here are some additional basic commands that you can try:
|open <directory path>||Opens the file you specified with the directory path.|
|ditto <original folder> <new folder>||Duplicate a file between folders.|
|caffeinate||Keeps your computer from going into sleep mode as long as Terminal is open|
|clear||Clears the Terminal screen|
|pwd||Returns the path to the working directory|
|..||Takes you to the Parent directory|
|man <command>||Takes you to the manual page for that command so you can read about the command, what it does, and how to use it.|
|say <type what you want your computer to say>||This command will result in your Mac speaking whatever you wrote after the say command.|
|history||View your Terminal command history.|
|history -c||Delete your Terminal command history.|