Class 1B - The Terminal#

Hide code cell content
from traitlets.config.manager import BaseJSONConfigManager
from pathlib import Path
path = Path.home() / ".jupyter" / "nbconfig"
cm = BaseJSONConfigManager(config_dir=str(path))
tmp = cm.update(
        "rise",
        {
            "theme": "sky", # https://revealjs.com/themes/
            "transition": "fade",
            "start_slideshow_at": "selected",
            "autolaunch": False,
            "width": "100%",
            "height": "100%",
            "header": "",
            "footer":"",
            "scroll": True,
            "enable_chalkboard": True,
            "slideNumber": True,
            "center": False,
            "controlsLayout": "edges",
            "slideNumber": True,
            "hash": True,
        }
    )

Lecture Outline#

  1. The Command Line (50 mins)

  1. Live Demo and Practice (10 mins)

  1. Preview of next week (20 mins)

The Command Line#

If you would like some additional notes and a much deeper explanation of the command line, I suggest the notes from Software Carpentry! They are truly 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 recommending 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 (Windows + R on Windows), 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

File System#

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#

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):

Lecture Demo#

Reproduce this structure in your repository#

The files should be named the same way, but you can leave them empty if you want.

../../_images/dir.png

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

  • code: edit the file in the Visual Studio Code text editor

3. Preview of next week#

Cool things with Processing.

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

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 Mac OS, Ubuntu, 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 on Canvas and GitHub