Learn Mac Terminal Basics

Curious about how to use the Mac Terminal as an alternative to the Finder or to set hidden macOS settings? Learn the basic commands to get started.
You can also watch this video at YouTube.
Watch more videos about related subjects: Terminal (43 videos).

Video Summary

In This Tutorial

Learn the basics of using Terminal on your Mac including navigation, file management, and key commands for more advanced tasks.

What Terminal Is

Terminal provides a text-based Command Line Interface as an alternative to the Graphical User Interface for interacting with files and folders.

Launching Terminal

Terminal is a pre-installed app. Launch it using Launchpad or any method you use to open apps.

Basic Navigation Commands

  • pwd: Display Present Working Directory
  • ls: List files and folders
  • cd foldername: Change directory into a folder
  • cd ..: Move up one directory level
  • cd /full/path: Navigate directly using full paths
  • cd ~/foldername: Use tilde as a shortcut to the Home folder

Listing Files With Options

  • ls -l: Long format list
  • ls -a: Include hidden files
  • ls -la: Combine options for detailed hidden file listing

File and Folder Management

  • mkdir foldername: Create a new folder
  • mv oldname newname: Move or rename a file
  • mv filename foldername/newname: Move and rename together
  • cp sourcefile destfile: Copy a file
  • rm filename: Delete a file (no safety net)

Opening Files

Use the open command to open files with the default GUI app or edit directly in Terminal with apps like pico.

Using Terminal Apps

  • pico: Basic text editor inside Terminal
  • top: View running processes, similar to Activity Monitor
  • Exit Terminal apps with Q or Control+C

Changing System Settings With Defaults

  • defaults write domain key value: Change hidden system settings
  • defaults delete domain key: Reset settings to default

Useful Terminal Shortcuts

  • Command+K: Clear Terminal screen
  • Tab: Autocomplete file and folder names
  • Quotes around names: Handle spaces in file or folder names
  • Up arrow: Scroll through previous commands
  • Option+Arrow: Move by word when editing commands
  • Multiple Terminal windows: Work in parallel in different locations

Learning More With Manual Pages

Use man commandname to view the manual page for any command. Use Spacebar to scroll and Q to quit.

Video Transcript

Hi, this is Gary with MacMost.com Here are the basics for using Terminal on your Mac. 
So when you normally use your Mac you're using what is called a Graphical User Interface that interacts with your files. For instance, you've got here a window. You use a pointer or trackpad you can click things or drag things, it's all part of the Graphical User Interface. But you can also use a Command Line Interface which doesn't require a mouse or trackpad at all, just you typing and reading plain text. To do that you use an app called Terminal. You can launch it the way you launch any app. It comes on your Mac. So I'm going to use Launchpad here to launch Terminal. 
Here I am in the Terminal window. It's just text here. I just type something and press Return and see the results. The Graphical User Interface, like this Finder window, there's a location that you're at. You're here in the Documents Folder. The same is true when you're working with Terminal. Now it lists your location here as well. Actually you can see but to have it spelled out for us we'll use our first command which is PWD which is Present Working Directory. When I type those 3 letters and then press Return I get some output. The output here is Users/macmost, in other words my MacMost folder in the Users folder. My Home directory in other words. Actually we knew that already because it showed us that in the line. This tilde character is an abbreviation for your Home folder. Now you won't see a list of files and folders here but we can ask for it. Now Ask is a command that will list these files. I press Return I can see a list of everything here. If I use the Finder and look in my Home directory I would see those folders there. The same ones listed here in Terminal. 
Now if I want to navigate down into one of those folders I would use another command. CD for change directory. I would type the directory name Documents. Then return. Now notice that the prompt here, in addition to having my Account and User name has Documents here. It did it before but using a tilde. The tilde character is an abbreviation for your Home folder. So the information was there if you know what to look for. Now if were list the files and folders here I would get a bigger list which includes a bunch of folders and even a file here. 
If you find these videos valuable consider joining the more than 2000 others that support MacMost at Patreon. You get exclusive content, course discounts, and more. You can read about it at macmost.com/patreon.
In any command, like ls, you can get it by using a dash and usually letters. So ls by itself will give you a list. But if we do dash l we get a list that looks like this. You can see each file and folder is on a separate line and includes lots of information like a date, for instance, and a file size. We could have also done ls dash A for all files, including invisible ones. When I do that you can see some invisible files that are here and you wouldn't see in the Finder. You can combine different modifiers like l and also a, like that. Now you will get a list in long form that also includes the invisible files.
Now we can use CD to go down into a folder. So, for instance, let's go down into the Temp folder here. I can do it like this and now I can list the files in the Temp folder. If wanted to go back up I can do CD and .., two dots represents going up one level. So I do that and now if I look at Present Working Directory I can see I'm back up at the Documents folder level. I can also just type a full path. So I can type CD and then slash then Users and then slash and then MacMost and then slash and Documents, like that, and get to my Documents folder. But remember tilde can be used as a substitute for Users slash Home folder. So I can use tilde slash Documents and end up in the same place. So that's great for just looking at your files and folders but how do you actually do things. 
Well, you use other things. For instance MKDIR is make directory. So I can make a new directory. I'll call this Temp 2, like that. Now when I list the files I see there is a Temp 2 directory that I created and I can dive down into that Temp 2 folder with CD. Then let's go back up a level with the two dots after CD, like that, and we've got this one file here, Testing.txt. We can move it or rename it using the MV command, which stands for move. Moving and Renaming is actually the same thing. You're moving the file to a new location. Now I can simply say I want to move Testing.txt to a file named Something else.txt, like that. Then when I list the files you can see that the file now has a new name. But I can also move it at the same time. So MV something else.txt I can move into that Temp 2 folder and call it say X.txt and now you can see it's gone from this level and is down into Temp 2 list of files there you can see how you can move and rename at the same time. You can also copy a file with CP. So I can copy x.txt to y.txt like that. Now I have duplicated the file so I have two of them. If I wanted to delete one of them I can use RM for remove. So y.txt will remove that file. You can see there's no safety net here. One of the reasons why some people are a little crazy about using Terminal. It gives you no leeway putting things into the Trash.  It just obeys your command and deletes that file. So always exercise a little extra caution when using RM.
You can also open a file in a regular app, a Graphical User Interface app will open. This is just like double clicking it in the Finder. If I did that with x.txt it will open it up here in the default app, which in this case is TextEdit. Now while you can open a file in any app in your Mac there are also times when you want to use that file through Terminal. There are apps that work inside of Terminal instead of in separate windows. For instance, PICO is a text editor. If I just type PICO and return I'm in this whole new interface here and I can type something and use the Commands below to save it. For instance, if I do command XX in here it will ask if I want to Save, Yes or No. I type yes. It will ask for a name. So I'll do Something.txt. Return and now if I look where I am here I see a file called Something.txt. There are a bunch of other apps that work in Terminal. If you really want to impress somebody just type the simple Command Top and it runs a an app called Top that shows you all of your Mac's running processes. It kind of looks like Activity Monitor but it's here inside of Terminal. To exit an app like this you can usually press Q or you can use Control C to terminate an app. 
One of the main reasons people use Terminal is not for any of the things I just showed you. But instead use a command called Default. What Default does is it allows you to set a System setting. You see there are more System Settings than are shown in the System Settings app. You can get to some of those hidden ones using the Default command. So often you'll see a post somewhere that says, in order to make your Mac behave like this, type this into Terminal. That command starts with the word Default. So, for instance, I'll type Default and then give it a command. Write, to write a new property and then do colon dot Apple dot screen capture. So that  prevents settings from going to change screen capture. The actual setting is the type setting. The type of file to save Screen Captures as, and I'm going to type jpg so it will now Save screen captures as jpeg instead of png. I press Return and now I changed that setting. To undo that I use the same command but png instead or Defaults and then Delete, to delete the setting. In other words to come back to whatever the app's default is and then Screen Capture and then type. I don't have to do anything at the end because the idea is to delete the setting where it specifies jpeg and go back to the default setting for that so now it will save as png's again. 
A few last tips. You may notice that sometimes I start with a fresh screen there. You can do that at any time with Command and K. Also you don't have to type out everything because there's autocomplete. If I do ls to see what's here and let's say I want to go down here to the Developer Folder. I can type CD and start typing developer, like that. But I don't have to complete the entire word. I can just press Tab and it will complete it for me. So you can very quickly get down into folders. 
Also notice that if there is a space in a name then things don't always work. If I do CD and I want to go down into some files you can see it doesn't work. It is looking for some and considers files to be separate because there is a space. An easy way to specify exactly what you want is to put quotes around anything with a space. So this will work. Also if you need to type similar commands over and over you don't have to start from scratch. Use the up arrow to see your previous commands. You can continue to up through everything and see exactly what you have typed in the past and then when you get to the command you want you can then just backspace over it and type something else and Return. You can also use the left arrow to go through the line and hold the Option Key down to jump by word. Also note you don't have to stay in one Terminal window. You can go and create a new window, like that, and have multiple Terminal windows open. So you can be working on one folder in one window and another folder in another window. Or have PICO editing a file in one window while you're going down and moving files around in another. 
Finally, if you want to know more about a command, like all modifiers you can use, type MAN for manual and then type the command. For instance, for ls here it will bring this up. You can use Spacebar to go by page, or the arrow keys to go up and down. You can see all the different modifiers and further explanation about how the command works and how to use it. Then just Q to quit out of the manual app. So if you want to learn more about using Terminal I suggest creating  a general folder, say your Documents folder. Use Terminal to go into that. Create some files. Move some files around just in that folder while testing things out and figuring out how things work. Hope you found this useful. Thanks for watching. 

Comments: 2 Comments

    Duug
    1 week ago

    Hi Gary, thanks for the tutorial on terminal. I got a strange result. When I open terminal, it shows my home folder name as: Home@192..Is the @192 indication that it is not my computer but somewhere on a network?

    1 week ago

    Duug: The number would seem to indicate that. But you say you didn't initiate an ssh session? If this is just your home Mac without any special configuration, I'm not sure why it would show you that.

Leave a New Comment Related to "Learn Mac Terminal Basics"

:
:
:
0/500 (500 character limit -- please state your comment succinctly and do not try to get around this limit by posting two comments)