Class 2A. Introduction to Markdown, the File System, and the Terminal (Command line)#

CommandPrompt CommandPrompt

Lecture Outline#

1. Announcements (5 mins)

2. Introduction to Markdown (5 mins)

3. The File System (20 mins)

4. The Command Line (45 mins)

Part 1. Announcements (5 mins)#

  • Lab 1 will be due Saturday September 17, 2022 at 6 PM

  • My office hours will be 30 minutes after every class on Tuesday, Thursday 17:00 - 17:30. You can also ask for help anytime on Ed Discussion, as well as visiting any of the labs.

  • Lab sessions start this week, and will not be recorded.

  • Correction: Last class I mentioned some keyboard shortcuts in VS Code to do some cool things, but it turns out I had manually configured those shortcuts on my computer so they wouldn’t work on your Visual Studio Code apps. Here are the actual (default) shortcuts:

Action

Shortcut on Mac

Shortcut on Windows

Insert additional cursor

Option + Click

Alt + Click

Insert cursor at end of each selected line

Shift + Option + I

Shift + Alt + I

Select all occurrences of current selection

Shift + Cmd + L

Shift + Ctrl + L

Select all occurrences of current word

Cmd + F2

Ctrl + F2

Add selection to next Find match

Cmd + D

Ctrl + D

Select current Line

Cmd + L

Ctrl + L

There are dozens more shortcuts, you can find the shortcuts here for:

Part 2. Introduction to Markdown (5 mins)#

Introduction to Markdown

  • What is Markdown?

“The overriding design goal for Markdown’s formatting syntax is to make it as readable as possible. The idea is that a Markdown-formatted document should be publishable as-is, as plain text, without looking like it’s been marked up with tags or formatting instructions. While Markdown’s syntax has been influenced by several existing text-to-HTML filters, the single biggest source of inspiration for Markdown’s syntax is the format of plain text email.”

Part 3. File System (30 mins)#

The file system organizes data on a device as a hierarchy of directories and files (like a tree). Each folder (AKA directory) has a name and can contain any number of files or subdirectories. Each file has a name. The user can change (navigate) directories in the hierarchy.

File System

File System Root - Children and Parents#

The tree is rooted at, well, the root.

  • There is only one root of a directory hierarchy. Every item in the tree is either a file or a directory (AKA folder).

  • You can think of a directory as a container that may contains files and/or other directories.

  • Files on the other hand hold information (and cannot contain other files or directories) .

If directoryC is contained in directoryP, then directoryC is a child of directoryP and directoryP is said to be the parent to directoryC.

  • A directory may have many children, but can only have one parent.

Absolute versus Relative Path#

  • The root of the file system is the directory “/”

  • There is only one root of a directory hierarchy.

  • A path to a new location (from your current location) can be specified as an absolute path from the root (this will work no matter where we are in the file system):

Activity: Let’s try to re-create that directory and file structure#

You will need the following commands:

  • cd : change directory

  • pwd : print working directory

  • mkdir: make directory

  • ls: list directory contents

  • touch: create an empty file with a specific name

  • rm: Delete a file (if you make a mistake)

  • rm -r: Delete a directory (if you make a mistake)

  • code: edit the file in the VS Code editor

../../../_images/relativepath.png

Break (5 mins)#

  • Let’s take a break!

Part 4. The Command Line (Terminal) (40 mins)#

If you would like some additional notes and a much deeper explanation of the command line (also known as the Terminal), I suggest the notes from Software Carpentry! They are excellent.

In particular, I suggest “Introducing the shell”, “Navigating Files and Directories”, and “Working with Files and Directories”

What is the Command Line?#

The command line is the text interface to the computer that accepts commands that the computer will execute. These commands include:

  • starting programs

  • navigating directories and manipulating files

  • searching, sorting, and editing text files

  • system and environment configuration

Why learn command line?#

The command line is the text interface to the computer. Understanding the command line allows you to interact with the computer in ways that you often cannot with the graphical user interface (GUI).

The command line is commonly used for scripting and automation of tasks and when accessing remote systems. It will also be useful to run programs that make use of the command line (eg. github).

Why use command line?#

The command line is part of the operating system (OS), which is software that manages your computer including all devices and programs.

  • Common operating systems include Windows, Mac OS, and Linux/Unix.

  • Some commands will be OS specific

You might be wondering why we would ever prefer command line over using the graphical user interface (GUI).

  • Certain tools may only be available to command line.

  • Sometimes command line is faster.

Command Line on Windows#

The command line on Windows dates back to the original Microsoft operating system called DOS (Disk Operating System) in 1981.

This command line interface is still part of all modern Windows operating systems and is accessible as the “Command Prompt”.

I am requiring you use GitBash instead of the default Windows Command Prompt.

Windows Terminal#

This is what the GitBash “Terminal” looks like. From here on out, whenever we say “Terminal”, we mean “GitBash on Windows”, “Terminal on macOS and Ubuntu”

CommandPrompt
  • The directory separator is a forward slash / for Macs/Ubuntu, and the opposite pointing slash on Windows \

  • However if you use GitBash, this should preserve your sanity and you should be able to use forward slash on Windows as well

  • In fact, many of the macOS/Ubuntu commands will also work in GitBash, but for completeness we will also share the other commands

Image source: Git for windows

Mac OS Command Line#

The command line for Mac OS uses the same commands as Linux. It can be opened using Finder then Utilities then Terminal.

CommandPrompt

Alternatively, we could type Cmd + spacebar, then type “Terminal” and press ENTER

Entering Commands#

Enter a command at a prompt. The prompt may be a > or a $ or customized by the user.

Press ENTER to execute the command.

On Windows, commands are mostly case-insensitive while on Mac/Linux they are case-sensitive.

Running commands CommandPrompt

Here are some useful Terminal Commands

  • cd : change directory

  • pwd : print working directory

  • mkdir: make directory

  • ls: list directory contents

  • rm: Delete a file

  • rm -r: Delete a directory

  • touch: create an empty file with a specific name

  • code: edit the file in the VS Code editor

Command-line Summary#

  • Briefly explain components of the Install Stack

  • Define command line and list some of its uses

  • Explain the purpose of an operating system

  • Know how to open the command line window on macOS and Windows

  • Enter commands in the Terminal and stop them

  • Define: file system, folder, file

  • Explain the difference between an absolute and relative path

  • Use command line shortcuts to save time

  • Be able to cancel a command (Ctrl+C)

  • Describe the full process of submitting a lab using GitHub and GitHub Classroom

Tips and Tricks with the Terminal#

  • Use the pwd command to find out where you are in the Terminal at any point!

  • Use “Up” and “Down” arrow keys to cycle through previously used commands.

    • This is a huge time saver!

  • Use Tab completion!!

    • Press tab to see available options

  • Use * to autocomplete partial matches

Conclusion#

  • The command line is the text interface to the computer that accepts commands that the computer will execute including running programs, manipulating files, and running scripts.

  • The command line allows for automation and more control than may be available in the user interface. It may also be the only way to interact with the machine if connecting via SSH.

  • The command environment allows for redirecting the standard input and output using input/output redirection and pipes.

  • You need to PRACTICE PRACTICE PRACTICE working in the Terminal: to get yourself used to it, I suggest not using the Finder/Explorer on your computer and use the Terminal for everything.

    • open will open a file in the default application

That’s it! See you Next Class!#

Additional Resources#

Supplementary video on absolute vs. relative paths#

IFrame(
    "https://www.youtube-nocookie.com/embed/sqX6hu7oEew", width="100%", height="500px"
)

Guide to the operating system for macOS users#

IFrame(
    "https://www.youtube-nocookie.com/embed/RX160bcMFuA", width="100%", height="500px"
)
## Guide to the operating system for Windows 10 users
IFrame(
    "https://www.youtube-nocookie.com/embed/egK5BKEn87c", width="100%", height="500px"
)