How to Use the Terminal
Here are the most important commands that you’ll need to know for CS61B:
This command will change your directory to
This command will tell you the full absolute path for the current directory you are in if you are not sure where you are.
~: shorthand for your home directory
.: shorthand for your current directory
This command will change your directory to the current directory (aka. do nothing).
..: shorthand for one parent directory above your current directory
This command will change your directory to its parent. If you are in
/workspace/day1/, the command will place you in
This command will list all the files and folders in your current directory.
You can also use
ls <directory> to list the contents of a different
directory – try
This command will make a new directory within the current directory called
dirname. You can think of a directory
as creating another folder on your local computer.
This command will create a file within the current directory called
filename. To create a text file, you would
run the command
This command will remove
file from the current directory. It will not work
file does not exist.
rm -r [dir]
This command will remove the
dir directory recursively. In other words, it will
delete all the files and directories in
dir in addition to
dir itself. Be
careful with this command!
This command is useful for inspecting the contents of files in the terminal without having to open them in a program. It is not as useful for large files (which can clutter the terminal) or non-text files (which will likely output gibberish).
cp lab1/original lab2/duplicate
This command will copy the
original file in the
lab1 directory and
duplicate file in the
mv lab1/original lab2/original
This command moves
cp, mv does not
leave original in the
mv lab1/original lab1/newname
This command does not move the file but rather renames it from
Here are some other useful tricks when working in a terminal.
- Your shell can complete file names and directory names for you with tab completion. When you have
an incomplete name (for something that already exists), try pressing the
tabkey for autocomplete or a list of possible names.
- You can copy-paste into the terminal. This is straightforward on Mac, but on Windows, right-click to copy and paste highlighted text.
- If you want to run the same command used recently, press the
uparrow key on your keyboard until you see the correct instruction. If you go too far, use the
downkey to go back. This saves typing time if you are doing repetitive instructions.
- You can have multiple terminals open at a time - this might help speed up your workflow if you’re running separate tasks that require the terminal.