Terminal Handout 1
Terminal Handout 1
Terminal
What’s Terminal?
Terminal on Mac, or the Command Line on Windows, provides a place for you to type
instructions (commands) for your computer to follow. With Terminal you can do all the
things you do with the user interface of your computer, but often more efficiently. It can
be used to:
• Access and change files
• Use Git for version control (keeping track of changes to files)
• Run programs
• Much more!
On MacOS
Type command + space to bring up spotlight, search for “Terminal”, hit enter to open the
Terminal app.
On Windows
Start -> type “cmd” or “Command Line”
Terminal Basics
When you use the command line to navigate the files on your computer it’s similar to
navigating the user interface, but some of the language is different. Instead of folders,
we refer to directories.
When you first open Terminal, you’ll see your prompt. For example, mine is:
maddiezug@ms-MacBook-Pro ~ %
Some commands are just one word or acronym, and others take arguments. Let’s take
a look at some commands and try them out.
Useful Commands
macOS: pwd
Windows: cd
Stands for “print working directory”, or "change directory". It prints the path to your
current directory.
macOS: ls
Windows: dir
cd path/to/directory
Stands for “change directory”. It moves you to the directory you specify in path/to/
directory. For Windows, if you don't specify any directory, it will print your current
directory. For Mac, if you don't specify any directory it will take you to your base
directory.
cd ..
mkdir nameOfDirectory
Stands for “make directory”. It makes a new folder in your current directory named
nameOfDirectory.
open nameOfFileOrDirectory
Opens the manual for the command, which describes what it does and how to use it. On
macOS Terminal, this will open a vim page. To exit the page type "q" for quit.
See the resource section of this handout for links to cheat sheets with tons more
commands to play with.
Useful Shortcuts
control-C
tab
up arrow
will let you navigate through previous commands you've typed. So if you want to run a
command twice but not type it both times you can use up arrow to get it back!
Try it out
Let’s try making a new folder in our Documents folder, and creating a text file inside with
our name in it, all using the command line. To start, open Terminal and type:
ls
You should see a list of files and folders from your base directory. Now type:
cd Documents
maddiezug@ms-MacBook-Pro Documents %
Since I’m now in my Documents folder. Next, try listing the contents of your directory
again:
ls
mkdir myFolder
I called my folder myFolder, but you can choose whatever name you want. Now I want
to navigate inside my new folder. Let’s type:
cd myFolder
Let’s check that my file was actually created. See what’s in myFolder:
ls
We should see myFile.txt listed. Great! Next I want to write my name into the file. With
the user interface, I would usually just open the file and type in my change. But with
terminal, I can add my text with a command:
In this command, the > means to pass the result of the first command to the destination
specified in the argument after the >. So echo will print “maddie” into my file! To confirm
that it worked, type:
cat myFile.txt
You should see your name printed! Awesome! You can also view your new file in
textEdit by typing:
open myFile.txt
Resources