Terminal Adventure

Lab setup

First, make sure you have completed the initial setup.

If you are part of a course

  1. Open Terminal. Run the update command to make sure you have the latest code.
    $ mwc update
  2. Move to this lab's directory.
    $ cd ~/Desktop/making_with_code/mwc1/unit1/lab_terminal
    
  3. Enter this lab's shell environment.
    $ poetry shell
    

If you are working on your own

  1. Move to your MWC directory.
    $ cd ~/Desktop/making_with_code
    
  2. Get a copy of this lab's materials.
    git clone https://git.makingwithcode.org/mwc/lab_terminal.git

This lab will explore one of the most important tools we'll use in this course: the Terminal. While it may seem complicated at first, it will quickly become your go-to tool for computer science class. The Terminal is what we'll use to navigate our filesystem, run code files, install software, and do all kinds of other tasks.

Terminal Adventure Lab

๐Ÿ’ป Open a Terminal window and run mwc update. It's a good idea to run mwc update every time you start a new lab to make sure you have the latest and greatest.

๐Ÿ’ป Open a new Terminal window and enter the commands below, one at a time. (Don't type the $.)

$ cd Desktop/making_with_code/mwc1/unit1/lab_terminal
$ poetry shell
$ ls
adventure
fancy_printing.py
poetry.lock
pyproject.toml
return_to_ship.py

return_to_ship.py is a runnable Python file (you can tell by the .py at the end). pyproject.toml and poetry.lock are a configuration files. You'll see them in every lab, and you may ignore them every time.

๐Ÿ’ป Run return_to_ship.py to see what happens:

$ python return_to_ship.py
    Your adventure has only just begun. You are not yet ready to
    return to the ship. More secrets await you in the ocean's depths.
    Use `ls` to look around, and use `cd adventure` to start the
    adventure...

Your challenge is to see if you can find the treasure and bring it back to the ship, using just the Terminal.

๐Ÿ’ป Begin by going into into the adventure directory and looking around:

$ cd adventure
$ ls
seafloor	sinking.txt

sinking.txt is a text file, so we can read it.

๐Ÿ’ป Use the cat command to print out the contents of a file:

$ cat sinking.txt

Terminal Commands

Here are some Terminal commands which might come in handy on your adventure.

CommandWhat it does
lsList what's in the current directory.
pwdPrints the "present working directory," or the path to where you are in the filesystem
cd ~Go to your home directory
cd somewhereGo to somewhere
cd ..Go to the parent directory
open file.txtOpens file.txt with its default program
cat file.txtPrints out the contents of file.txt
python fun.pyRuns the Python program fun.py
mv old.txt new.txtRenames a file from old.txt to new.txt. Also works for directories.
mv file.txt dirMoves a file to directory dir.
cp old.txt new.txtCopy a file from old.txt to new.txt.
mkdir bagCreates a new directory called bag
rm file.txtremoves (deletes) the file file.txt
rm -d dirremoves (deletes) the directory dir
rm -r dirrecursively removes (deletes) the directory dir and all subdirectories and files within that directory. Be careful, this is a powerful tool!