Chapter 3 - What is the Terminal?

Introduction

What is the terminal? It's a place where you can interact with your computer through text. Have you ever right clicked on your Desktop to create a new folder (aka directory)? You can do that in terminal with a simple text command. How about double clicking a folder to access a file inside? There's a command for that too! Deleting directories, creating files, finding files, moving files from one directory to another? All of these are easy to do from your terminal with a few keywords.

Why would I want to use terminal?

You probably don't... but you will! As a developer the terminal is a key tool in your tool belt. You can navigate more quickly and interact with your machine in more sophisticated ways, plus most of your friends will think you're some super savvy hacker. More importantly, it's a skill that is expected of developers because some tools that developers use are only available in the terminal.

So what's Git Bash?

Terminal is the Mac command line tool. Windows has its own command line tool, Command Prompt. The truth is you may end up using either. You can perform most actions from either Git Bash or Command Prompt but the commands themselves are different - kind of like how you can express the same thing in English or Spanish, but the words differ.

Git Bash allows Windows users to use the same commands and tooling that a Linux/Unix based system uses. Linux/Unix is another operating system like Windows or MacOS. Git Bash can be helpful if your team is deploying code to a Linux server. For the purposes of our class we'll be using Linux style commands, so you'll need Git Bash to execute them, but we won't judge you if you decide to use Command Prompt after the course.


A Closer Look

The terminal/Git Bash is a way to interact with your computer via text only.

Creating directories and files on your computer through the terminal is much more efficient than creating them through the graphical interface. The terminal will also be a vital tool when we start using version control software which we'll learn about shortly.

Developers use the terminal every day at work. It may feel clunky at first, but with practice it will make you a much better developer.

How can I perform simple operations with my terminal?

The below cheat sheet is a useful guide for the most commonly used terminal commands. There are many others, but these are the ones on which we will focus for now.

  • cd (changes directory)

  • cd ~ (changes to home directory)

  • cd .. (moves up one directory)

  • ls (lists files in folder)

  • pwd (shows current directory)

  • mkdir <FOLDERNAME> (creates new directory)

  • touch <FILENAME> (creates a file)

  • open . (opens the current folder. MAC SPECIFIC) or explorer . (opens the specific file. WINDOWS SPECIFIC)

When typing a file or directory name, we can use the tab key to auto-complete that file or directory name.

Auto-completion only works when we have a unique file or directory name that matches.


Practice

What if I want to practice these commands?

This handy video can walk you through the below steps:

Then you are exactly the student we are looking for - hungry for knowledge and eager to get your hands dirty!

Open the Terminal/Git Bash and (using only the command line) create the following:

  1. Navigate to your Desktop or Directory: cd Desktop

  2. Once there, create a new directory named test: mkdir test

    • NOTE: When naming your directories and files, we generally want to avoid having spaces in the name. If you wish to have a descriptive name, it's recommended you use underscores. So, instead of naming a directory java prework, name it java_prework.
  3. Create a new txt file called sample: touch sample.txt

  4. Navigate into the test directory: cd test

  5. Check to see what's inside (it should be empty): ls

  6. Navigate back to Desktop: cd ..

  7. Move the sample.txt file into the test directory: mv sample.txt test

  8. Make sure this was successful: cd test press enter and then ls

  9. Time for some independent learning. Google to find a way to rename the sample.txt file to example.txt.

  10. Pat yourself on the back! You just took your first steps towards becoming a developer.

Assignment (Required)

For this assignment, you'll be listing out the steps required for basic folder navigation using the Terminal or GitBash (depending on your OS).

Instructions

  1. Start by opening Terminal / GitBash.

  2. Write the command to navigate to the Home Directory.

  3. Change directories to your Desktop.

  4. Make a new directory called, "prework", and change into that directory.

  5. Create a new file called, "index.html" and list out every file/folder within "prework".

  6. Change directories back to home.

  7. Type the command to show the current working directory.

  8. Change directories back into "prework" and open the current folder.

Submission

Write your answers in a Google Document titled, "Terminal & GitBash Prework Assignment". You'll be submitting a link to your Google Document in Bootcampspot so make sure that you choose the "Anyone with the link can View" share option! Be sure to submit this link under the assignment, "Pre-work: Terminal & GitBash" in Bootcamptspot.

If you have any issues submitting your prework, remember that you can always check out this video for step-by-step instructions on how to do so! Prework Submission Video