Module 5: 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?

The terminal will quickly become a key tool in your tool belt. You can navigate more quickly and interact with your machine in more sophisticated ways, plus most your friends will think you're some super savvy hacker. More importantly, it's a skill that is necessary for some of our tools, as they are only interacted with using 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 in Windows machines 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.

It may feel clunky at first, but with practice it will make it so much easier to navigate through your directories and files, and interact with some of our technologies.

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?

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

This handy video can walk you through the below steps:

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 names 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 terminal prework, name it terminal_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.