Skip to content

Latest commit

 

History

History
119 lines (80 loc) · 4.67 KB

terminal-basics.md

File metadata and controls

119 lines (80 loc) · 4.67 KB

Logo

Terminal Basics

A short explanation of what terminal is and some important commands

Table of Contents

What is Terminal?

Terminals, also known as command lines or consoles, allow us to accomplish and automate tasks on a computer without the use of a graphical user interface (source: IT Connect)

Getting Terminal Set Up

If you are on Mac or Linux computers, you should have terminal already installed. On windows computers, the command line uses slightly different syntax so getting set up will require a few extra steps.

This article explains how to get terminal set up on windows

Note this will involve installing Visual Studio Code as well as Git/Git Bash (which you may already have installed if you use Git or GitHub)

In order to illustrate how terminal works, let's walk through a very simple example scenario

Example Scenario (tasks)

  1. Make a folder on the Desktop titled My Folder
  2. Make a folder inside My Folder called Contents
  3. Make a file in My Folder/Contents called foo.txt
  4. Make another file in My Folder/Contents called bar.txt
  5. Go back to My Folder and clone in one of our projects from our GitHub
  6. Check that My Folder contains two subfolders: Contents and the project we just cloned

Accomplishing the Task (without Terminal)

Note I am going to describe the process using Mac OS, however it will look almost identical on Windows or Linux machines.

  1. Open Finder application and navigate to Desktop
  2. Right click and select New Folder, title it My Folder
  3. Go to My Folder, right click and select New Folder, title it Contents
  4. Open textEdit application and make new file called foo.txt, write nothing and save to Contents
  5. In textEdit application, make another new file called bar.txt, write nothing and save to Contents
  6. Open GitHub Desktop and go through the steps described here
  7. Reopen Finder and double check the contents of my-folder for Contents and the project we just cloned

The steps above involve 3 separate applications, lots of navigating between applications and a lot of extra steps

Accomplishing the Task (with Terminal)

  1. Open terminal application
  2. run $ cd Desktop
  3. run $ mkdir my-folder
  4. run $ cd my-folder
  5. run $ mkdir Contents
  6. run $ touch foo.txt
  7. run $ touch bar.txt
  8. run $ cd ..
  9. run $ git pull <PROJECT-URL> (where project URL is the actual URL for the project)
  10. run ls (to list folder contents)

That may seem like more steps, but consider what would take more time, doing all the subtasks in the non-terminal section or simply typing the commands in the terminal section?

For more info on the git command and using terminal for Git/GitHub, see here

(Basic) Essential Commands

An important thing to realize about terminal is that you are always somewhere -- ie. in some folder on a computer. When you first launch, this will be the HOME folder. As you navigate through, this will change.

ls

Running ls will list the contents of the current folder (subfolders and files)

cd

cd stands for change directory You can use it to enter a immediate subdirectory from the current directory

  • $ cd my-subfolder

Or you can provide a whole filepath to go to any directory

  • $ cd "Desktop/My Folder/Contents"

You can also cd out of a given directory to a parent directory

  • $ cd .. (see how this was used in the example above)

mkdir

mkdir will create a folder:

  • $ mkdir my-new-folder-name

touch

touch will create a new file

  • $ touch my-new-file.txt
  • $ touch my-new-python-file.python