πŸ›£οΈ Week 01 - Set up your computer and meet the Terminal

2023/24 Winter Term

Author
Published

15 January 2024

Welcome to the first lab session of the course! When you come to the lab, ensure you have your laptop. You will need it to complete the lab exercises.

Our main objective today is to get you all set up with the tools you will need for the course. If you have done the set-up already, that is awesome! You can practice with the Terminal – something you will have learned about in the πŸ—“οΈ Week 01 lecture.

πŸ₯… Learning Objectives

Your progress will depend on whether you followed the πŸ“š W01 Lab Preparation steps or not:

By the end of this session, you will be able to:

  • Identify the β€˜Terminal’ app on your computer
  • Open a bash terminal
  • Interact with the bash terminal
  • Create and edit plain text files using the bash terminal

It is OK! Just reserve some time to practice with the terminal before the next lecture. You can ask questions on Slack anytime (even after the lab) if you get stuck (#help-installation).

By the end of this session, you will be able to:

  • If on Windows, download and install GitBash
  • Practice how to search online for solutions to common installation problems
  • (time pending) Learn the basics of the bash terminal

πŸ“‹ Lab Tasks

Here are the instructions for this lab:

🀝 Part I: Introductions (20 min)

πŸ§‘πŸ»β€πŸ« TEACHING MOMENT: Your chance to get to know your classmates and instructors.

πŸ’‘ TIP: Whenever you see a πŸ§‘πŸ»β€πŸ« TEACHING MOMENT in the lab roadmap, it means your class teacher will be talking to you, and they deserve your full attention. Please do not work on the lab exercises during these moments. You will have plenty of time to do so later on.

βš™οΈ Part II: Setup (15 min)

πŸ’‘ TIP: This part contains 🎯 ACTION POINTS. Whenever you see these words in the lab roadmap, you are to work independently or with others, and the class teacher will go around the room to help you if you need assistance.

🎯 ACTION POINTS

  1. Complete Step 1: Install the Bash Terminal on the πŸ“‹ Getting Ready page.

⚠️ NOTE: It is VERY common for anyone (not just students) to encounter issues when installing software. If you get a weird error and spend the entire lab troubleshooting, this is absolutely common! You will still learn a lot, trust us! Each computer is different, and even instructors might struggle to understand what is going on. This is your opportunity to learn how to effectively search for solutions online and ask for help on Slack.

πŸ“ Part III: The terminal (50 min)

πŸ§‘πŸ»β€πŸ« TEACHING MOMENT: Your class teacher will demonstrate how to open the terminal app and how to interact with it, and you will be following them step by step.

Step 1: Create a plain text file (10 min)

Click here to see the 🎯 ACTION POINTS

Windows logo Windows users

  • Hello, world! I am taking DS105W, and this is my first plain text file.
Apple logo macOS users

  • Hello, world! I am taking DS105W, and this is my first plain text file.

Step 2: Locating yourself (15 min)

Click here to see the 🎯 ACTION POINTS

Can you locate the hello.txt file you just created using the command line? We will follow the instructions below step by step while answering your questions.

  1. Open the bash shell using the instructions from Step 1 above

  2. Type pwd and hit ENTER:

     pwd

    You should get a string of text indicating the full path of where you are inside the terminal. (You will learn about the hierarchy of directories in the lecture later in the week.)

  3. Are you currently in your $HOME directory? To find out where your home directory is, use the following command:

     echo $HOME
  4. Are there any files/sub-directories in your current directory? Use ls to investigate:

     ls

    or

     ls .
  5. Are there any hidden files?

     ls -a
  6. Now, let’s explore what is above your current directory:

     ls ..
  7. Do you understand what the different dots . and .. represent 1? This will be extremely important once we start doing advanced stuff with the terminal and web scraping.

  8. Now, more than just look at the parent directory, let’s move there:

     cd ..

    Then, use the same ls commands you explored above. Did you notice anything different now?

  9. Let’s force ls to print the same information in a different format. Try the following command:

     ls . -lth

    What do the -l, -t, and -h arguments mean? You can find out by looking at the ls manual:

     man ls

    Use the arrow keys on your keyboard to scroll up and down the manual. Type the character q when you are done browsing.

  10. Use what you have learned so far to go to the directory where the hello.txt file is. Hint: if you get stuck, try pwd again and compare the output you get now to the one you got the first time you used this command.

Whenever we show you the β€œ$” sign at the beginning of the code snippets, it just indicates that you are to type this inside the Terminal. Don’t type the β€œ$” sign!

$ pwd

Step 3: Wandering away from $HOME (15 min)

Click here to see the 🎯 ACTION POINTS

Now, given what we practiced, try to follow the steps below (help from colleagues is fine) and take note of your answers to the questions.

We will go over the solutions once everyone has finished this step.

  1. Go to the root of the filesystem:

     cd /

    Or, if you are on Windows:

     cd /c
  2. What do you see with ls? What does it mean?

  3. Walk around freely up and down the directories and sub-directories you encounter. Check the links on πŸ”– Week 01 Appendix - Linux and the Terminal page to understand where you are navigating.

  4. Are there any directories under / that you could not enter? Why?

  5. Go back $HOME

Step 4: Creating and editing files and directories (10 min)

Click here to see the 🎯 ACTION POINTS

  1. Go to your $HOME directory or a folder of your choice. Then, create and enter a directory; let’s call it DS105W:

     cd $HOME
     mkdir DS105W
     cd DS105W
  2. Create a text file and call it README.txt:

     touch README.txt
  3. Now, using Windows Explorer or Finder, open the directory where you created the README.txt file. You should see an empty file.

  4. Using the text editor of your choice, write something to the file (your name, a verse, a sentence, whatever comes to mind) and save it.

  5. Now, go back to the terminal and use cat to print the contents of the file:

    cat README.txt
  6. Now close the terminal and open it again. Can you still see the file you created? If not, why?

Footnotes

  1. See the answer to this question on Stackoverflow: β€œWhat is double dot(..) and single dot(.) in Linux?β€β†©οΈŽ