By the end of this lab, you should have submitted the lab with
python3 ok --submit. You may submit more than once before the
deadline; only the final submission will be graded.
Hello! The first thing you probably noticed about these computers is that they don't have Windows or MacOS installed. And you're right — they're running UNIX (Ubuntu to be exact). But fear not! We'll get you familiar with this new system in no time!
This lab explains how to use the school computers for CS 61A labs and also teaches the basics of using a UNIX terminal. Lab 1 discusses how to use your own computer for CS 61A.
In CS 61A, you will be interacting with a variety of programs:
Before we continue, make sure you have set up your class account by doing the following:
??replaced by your unique two or three letters).
Opened a terminal (by typing
ctrl-alt-t) and entered registration
information. Make sure you enter your berkeley.edu email address.
If you made a typo (e.g. misspelled your name), don't worry. After completing the registration process, you can type
re-registerinto your terminal and hit enter. This will restart the registration process.
Changed your password (by typing
ssh update into the terminal).
When you are typing in your old and new passwords, no characters will show up in the terminal — this is a security feature, not a problem.
Please do not forget your login information. In particular, memorize
??replaced by your unique two or three letters)
If you forget your login at anytime during the class, you can ask your TA to find it for you. However, if you forget your password, you will have to email email@example.com or go to 333 Soda.
Double check that your information is correct by running the
check-register command. If you find errors (e.g. you typed your last
name as "ssh update"), fix them immediately by running the
If you don't have access to a school computer for this lab, you can still try it out: refer to lab 1 for more details about setting up your home computer.
The terminal is a program that allows you to talk to your computer by entering commands. No matter what operating system you use (Windows, MacOS, Linux), the terminal will be an essential tool for CS 61A.
On a school computer, you can start the terminal in various ways:
Click on the launcher in the top left corner and type "terminal":
Both methods will open the terminal, which looks like this:
In the image above, the prompt says
hive5. Depending on which
school computer you are using, your prompt might say something
The terminal lets you give commands to your computer. Try this command:
echo "Hello world"
Your terminal will repeat "Hello world" back to the screen. The
command just tells your terminal to repeat the words you typed. Not too
impressive just yet, but it turns out the terminal can do a lot more!
On Windows or MacOS, you are probably familiar with folders and files, with which you can interact by dragging and dropping icons. Today, we are getting rid of the icons and using just the terminal to manage our files and folders!
Note: most school computers support graphical interfaces for file management, much like Windows and MacOS. If you really, really, really don't want to use the terminal for file management, that's okay. However, learning to use the terminal pays off!
With the terminal, you can do everything that a graphical filesystem can do — and more!
The first command we'll use is
ls (the letter
l and the letter
s). Try typing it into the terminal!
hive5  ~ # ls Desktop/ Documents/ Downloads/ ...
Depending on what computer you are using, the output that you see after typing
lsmight be different.
ls command lists all the files and folders in the current
directory. A directory is another name for a folder (such as the
When you open a terminal, you will start from the home directory.
Notice that your prompt (
hive5  ~ #) has a tilde
~ in it. Your
prompt helpfully tells you your current directory — in this case, your
current directory is
~, which stands for the home directory.
Our next command is called
mkdir. Try typing the following command
into your terminal:
mkdir command makes a new directory (i.e. makes a new
folder). Notice that, unlike
ls, we don't just type
and press enter. We also need to specify an argument to the command
(the argument is
lab0 in this example). For
mkdir, the argument is
the name of the directory we want to create.
Some commands always require arguments to work, like
mkdir. Other commands can work just fine without supplying any arguments, like
Now that we've made our
lab0 directory, let's make sure it is
actually there. Use the
ls command to verify that
lab0 shows up in
our list of directories.
To move into another directory, we use the
cd command. Try typing the
following command into your terminal:
cd command will change directories — in other words, it
moves you into the specified folder. In the example above, we chose to
move into the
Notice that the
~ in your prompt turned into
~/lab0. Again, the
prompt will tell you what your current directory is. In this case, we
are in the
lab0 directory, which is located within the home directory
If you use the
ls command now, you'll notice that no output shows up.
This makes sense, since we just created the
lab0 directory and we
haven't added any files to it. We'll come back to this later.
For now, let's get back to our home directory. There are a few ways to do this:
cd ..(two dots). The
..means "the parent directory". In this case, the parent directory of
lab0happens to be our home directory, so we can use
cd ..to go up one directory.
cd ~(the tilde). Remember that
~means home directory, so this command tells your terminal to change to the home directory, no matter where you currently are.
cd(that is, the
cdcommand with no arguments). In UNIX, typing just
cdis a shortcut for typing
We now know how to see, create, and move to directories. Our last
command involving directories will be to delete them using the
First, let's create a temporary directory:
If you use the
ls command, you should now see
tmp listed as a
Next, let's delete the
rm -r tmp
rm command will remove files and directories from your
filesystem. By itself (that is, without the
only removes files. However, since we are removing a directory, we need
-r to recursively remove the
tmp directory and any
tmp might contain (the process is called "recursive"
because, in order to remove
tmp, we have to remove everything inside
As you've seen, some commands require arguments, like
mkdir. Other commands do not require any arguments in order to work, like
ls. In addition, most commands can also be given flags, like the
rm. Flags are ways to specify modified behavior for commands — for example,
rmby itself only removes files; using
rmto remove directories.
So far, we have learned how to do the following with directories (folders):
ls: list the files and folders inside of the current directory
mkdir: make a new directory
cd: change directories
rm -r: remove a specified directory
Directories are not very useful if they don't contain any files. In this section, we walk through some more commands that allow you to interact with files.
For this section, let's start back in our home directory. Recall that we can do this by simply typing
into our terminal. Your prompt should now say
There are many different ways to create files. For this class, you will usually be using a text editor to directly write the file, much like how you would edit a Word document in Microsoft Word. We'll talk more about text editors in Lab 1.
For now, we'll just download a file called
unix.txt, which can be
found here. In this class, you will start most
homeworks and projects by downloading a file.
The default location for downloads on the school computers is in the
Downloads directory. Let's change into that directory using our
You can use the
ls command to verify your
unix.txt is in this
On Windows and Mac, much of your interaction with files is likely spent
dragging them from folder to folder. UNIX provides a way to move files
Remember that we created a directory called
lab0. Let's move
mv unix.txt ~/lab0
mv command moves one file/directory into another
file/directory. Here, we are moving the
unix.txt file into the
lab0 directory, which is inside the home directory.
To verify that the
mv command work, do the following:
lsto check that
unix.txtis no longer in our current directory (which is the Downloads directory).
lab0directory. Your prompt should now show
lsto verify that
unix.txtshows up in
Files are useful because they contain information. Let's see what
unix.txt contains. Type in the following command:
This prints out a list of all the useful UNIX commands we've seen so
cat command prints the contents of a file to the screen.
This is a fast way to verify that a file is correct or to read what a
file contains. For example, if you forget any UNIX commands in today's
lab, you can quickly
cat unix.txt to read about them.
To rename files on Windows or MacOS, you would click on the name of the file and type in the new name.
Renaming files with the terminal can be a little confusing at first.
Try the following command in the terminal (from the
mv unix.txt unix_commands.txt
ls, you'll see that
unix.txt is gone — in its place is a
unix_commands.txt. Furthermore, typing
unix_commands.txt will print out the same list of UNIX commands.
It appears that we renamed
unix_commands.txt by using
mv command! Here's how to think about it:
mvwill move the contents of a file/directory into another file/directory. In the previous section, we moved a file into a directory.
unix.txt) into another file (
unix_commands.txt). While we are technically moving file contents, this is effectively the same thing as renaming a file!
This can be a bit confusing if you're seeing it for the first time, so make sure you understand it before you move onto the next section.
Note: Suppose you already have two files,
bob.txt, and you issue the command:
mv alice.txt bob.txt
This will overwrite the old contents of
bob.txtwith the contents of
alice.txt! UNIX won't warn you about overwriting, so be careful when using the
Sometimes, it is useful to have multiple copies of a file. Try the following command:
cp unix_commands.txt lab0.txt
cp command copies the contents of one file into another
ls, you will see that the
lab0 directory now contains
cat will verify
that both files have the same contents.
Suppose we also wanted to copy the
unix_commands.txt file to our home
directory. Here's one way to do it:
Next, use the following command:
cp lab0/unix_commands.txt .
Don't forget the dot at the end!
The first argument (
lab0/unix_commands.txt) tells the terminal to
look in the
lab0 directory to find
The second argument
. tells the terminal to copy
to the directory
.. Just as two dots (
..) represents the parent
directory, a single dot (
.) represents the current directory (the
directory we're in right now).
Now that we're in the home directory, we can use
ls to verify
that there is a copy of
hive5  ~ # ls Desktop/ ... unix_commands.txt ...
cat unix_commands.txt will show the same output of UNIX
Recap: we've seen two special directories: two dots
..represents the parent directory (one directory up), while a single dot
.represents the current directory. You can use these special expressions with any command that deals with directories. For example, you can
mva file to the current directory with the command
mv some_file .
rm command we
introduced earlier. We originally used the
-r flag to remove directories. Now we will use
rm without the
to remove a file. Type this into your terminal:
This will delete the copy of
unix_commands.txt that is in our current
directory (which is the home directory). A quick
ls will show you
unix_commands.txt is gone.
Warning: Unlike on Windows and MacOS, there is no friendly Recycle Bin or Trash from which you can restore deleted files. In UNIX, when you
rma file, it's gone. You can't "undo"
rm, so think twice (and thrice!) before using the
In this section, we learned the basics of manipulating files:
cat: displays the contents of a file on the screen
mv: moves a file/directory to another file/directory. When moving one file to another, we are effectively renaming the file!
cp: copies a file to another file/directory.
rm: removes a file. When using the
rmwill delete directories.
In addition, we learned about two special directories:
.. (the parent
. (the current directory).
If you ever come across a terminal command with which you are
unfamiliar, you can use a command called
man command will show the manual pages (reference pages) for
another command. In the example above, we ask the terminal to show the
manual pages for the
ls command. As you skim through the manual
pages, you'll notice that
ls can do a lot more than just list the
contents of a directory!
man is a great way to learn more about new
commands and even commands that you think you already know.
Note: Some school computers do not have the
mancommand installed, so you might get an error. That's okay — if
manever fails, Google is your friend!
While the primary programming language in CS 61A is Python, it is important to know how to navigate through the UNIX filesystem to manage your class assignments. You will also be interacting with the Python interpreter from your terminal, whether you are using a school computer or your home computer.
In addition, if you continue with computer science after 61A, you will definitely interact more with UNIX and the terminal. For that reason, be sure to review today's lab if you have any questions!
At this point, if you have finished the lab early, you can begin on Lab 1. Lab 1 walks you through how to pick a text editor, and how to write, test, and submit your first homework assignment for this class.
Prompt: displays certain information every time the terminal is ready to receive new commands. For example, your prompt might look something like this:
hive5  ~ #
Usually, prompts will tell you your current directory (in the example
above, the current directory is
ls: list the files and folders inside of the current directory
mkdir: make a new directory. For example,
mkdir lab0creates a directory called
cd: change directories. For example,
cd lab0changes directories to
rm -r: recursively remove a specified directory. For example,
rm -r lab0removes the
lab0directory and all files and subdirectories inside it.
cat: displays the contents of a file on the screen. For example,
cat unix.txtshows the contents of the file
mv: moves a file/directory to another file/directory. For example,
mv file1 file2moves the contents of
file1into a (possibly new) file called
file2. When moving one file to another, we are effectively renaming the file!
cp: copies a file to another file/directory. For example,
cp file1 file2copies the contents of
file1into a file named
rm: removes a file. For example,
rm file1deletes the file called
echo: displays words on the screen
man: displays manual pages for a specified command