Introduction to Terminal - GitHub Pages · 2017-10-06 · Introduction to Terminal Computing in...

56
Introduction to Terminal Computing in Optimization and Statistics: Lecture 1 Jackie Baek MIT January 10, 2017

Transcript of Introduction to Terminal - GitHub Pages · 2017-10-06 · Introduction to Terminal Computing in...

Page 1: Introduction to Terminal - GitHub Pages · 2017-10-06 · Introduction to Terminal Computing in Optimization and Statistics: Lecture 1 Jackie Baek MIT January 10, 2017. ... (e.g.

Introduction to Terminal

Computing in Optimization and Statistics: Lecture 1Jackie Baek

MIT

January 10, 2017

Page 2: Introduction to Terminal - GitHub Pages · 2017-10-06 · Introduction to Terminal Computing in Optimization and Statistics: Lecture 1 Jackie Baek MIT January 10, 2017. ... (e.g.

Overview

Introduction & Motivation

Navigation commands

FilesBasic file commandsFile path shortcutsHidden Files.bashrc / .bash profile

Redirection

SSH

Simple Pattern Matching

How bash worksEnvironment Variables

Documentation

Key Takeaways

Page 3: Introduction to Terminal - GitHub Pages · 2017-10-06 · Introduction to Terminal Computing in Optimization and Statistics: Lecture 1 Jackie Baek MIT January 10, 2017. ... (e.g.

What is the terminal?

Page 4: Introduction to Terminal - GitHub Pages · 2017-10-06 · Introduction to Terminal Computing in Optimization and Statistics: Lecture 1 Jackie Baek MIT January 10, 2017. ... (e.g.

What is the terminal?

I The terminal is a text-based interface to interact with thecomputer.

I Alternate names: console, shell, command line, commandprompt

Page 5: Introduction to Terminal - GitHub Pages · 2017-10-06 · Introduction to Terminal Computing in Optimization and Statistics: Lecture 1 Jackie Baek MIT January 10, 2017. ... (e.g.

Example

I Say you want to delete all files in a directory that end with.pyc

$ rm *.pyc

I This is possible to do without the terminal, but it requiresmuch more effort.

Page 6: Introduction to Terminal - GitHub Pages · 2017-10-06 · Introduction to Terminal Computing in Optimization and Statistics: Lecture 1 Jackie Baek MIT January 10, 2017. ... (e.g.

Why should I learn it?

I You can do almost everything using just the terminal.

I It can do many tasks faster than using a graphic interface.

I It is sometimes the only option (e.g. accessing a client’sserver using SSH).

I It is universal.

Page 7: Introduction to Terminal - GitHub Pages · 2017-10-06 · Introduction to Terminal Computing in Optimization and Statistics: Lecture 1 Jackie Baek MIT January 10, 2017. ... (e.g.

Terminal Basics

I We will be using a shell called bash: a program that interpretsand processes the commands you input into the terminal.

I The shell is always in a working directory.

I A typical command looks like:

$ command <argument1> <argument2> ...

Page 8: Introduction to Terminal - GitHub Pages · 2017-10-06 · Introduction to Terminal Computing in Optimization and Statistics: Lecture 1 Jackie Baek MIT January 10, 2017. ... (e.g.

Basic navigation commands

pwd: prints working directory.

$ pwd

/Users/jackiebaek

ls: lists directory contents.

$ ls

Applications Movies

Desktop Music

Documents Pictures

cd <directory>: change working directory to new directory.

$ cd Documents

$ pwd

/Users/jackiebaek/Documents

Page 9: Introduction to Terminal - GitHub Pages · 2017-10-06 · Introduction to Terminal Computing in Optimization and Statistics: Lecture 1 Jackie Baek MIT January 10, 2017. ... (e.g.

Basic navigation commands

pwd: prints working directory.

$ pwd

/Users/jackiebaek

ls: lists directory contents.

$ ls

Applications Movies

Desktop Music

Documents Pictures

cd <directory>: change working directory to new directory.

$ cd Documents

$ pwd

/Users/jackiebaek/Documents

Page 10: Introduction to Terminal - GitHub Pages · 2017-10-06 · Introduction to Terminal Computing in Optimization and Statistics: Lecture 1 Jackie Baek MIT January 10, 2017. ... (e.g.

Basic navigation commands

pwd: prints working directory.

$ pwd

/Users/jackiebaek

ls: lists directory contents.

$ ls

Applications Movies

Desktop Music

Documents Pictures

cd <directory>: change working directory to new directory.

$ cd Documents

$ pwd

/Users/jackiebaek/Documents

Page 11: Introduction to Terminal - GitHub Pages · 2017-10-06 · Introduction to Terminal Computing in Optimization and Statistics: Lecture 1 Jackie Baek MIT January 10, 2017. ... (e.g.

Tab and arrow keys are your friends

I Use tab to autocomplete commands and file paths.

I Use ↑ and ↓ arrow keys to navigate through your commandhistory.

I Use clear or cmd-k to clear screen.

Page 12: Introduction to Terminal - GitHub Pages · 2017-10-06 · Introduction to Terminal Computing in Optimization and Statistics: Lecture 1 Jackie Baek MIT January 10, 2017. ... (e.g.

What is a file?

A file is a container of data (0’s and 1’s).

A file name usually has an extension (e.g. .pdf, .doc, .csv), butthese are just conventions.

A file is contained in a directory (folder). Files within the samedirectory have unique names.

Every file and directory has a unique location in the file system,called a path.

I Absolute path:/Users/jackiebaek/Dropbox/Documents/hello.txt

I Relative path (if my current working directory is/Users/jackiebaek/Dropbox): Documents/hello.txt

Page 13: Introduction to Terminal - GitHub Pages · 2017-10-06 · Introduction to Terminal Computing in Optimization and Statistics: Lecture 1 Jackie Baek MIT January 10, 2017. ... (e.g.

What is a file?

A file is a container of data (0’s and 1’s).

A file name usually has an extension (e.g. .pdf, .doc, .csv), butthese are just conventions.

A file is contained in a directory (folder). Files within the samedirectory have unique names.

Every file and directory has a unique location in the file system,called a path.

I Absolute path:/Users/jackiebaek/Dropbox/Documents/hello.txt

I Relative path (if my current working directory is/Users/jackiebaek/Dropbox): Documents/hello.txt

Page 14: Introduction to Terminal - GitHub Pages · 2017-10-06 · Introduction to Terminal Computing in Optimization and Statistics: Lecture 1 Jackie Baek MIT January 10, 2017. ... (e.g.

What is a file?

A file is a container of data (0’s and 1’s).

A file name usually has an extension (e.g. .pdf, .doc, .csv), butthese are just conventions.

A file is contained in a directory (folder). Files within the samedirectory have unique names.

Every file and directory has a unique location in the file system,called a path.

I Absolute path:/Users/jackiebaek/Dropbox/Documents/hello.txt

I Relative path (if my current working directory is/Users/jackiebaek/Dropbox): Documents/hello.txt

Page 15: Introduction to Terminal - GitHub Pages · 2017-10-06 · Introduction to Terminal Computing in Optimization and Statistics: Lecture 1 Jackie Baek MIT January 10, 2017. ... (e.g.

What is a file?

A file is a container of data (0’s and 1’s).

A file name usually has an extension (e.g. .pdf, .doc, .csv), butthese are just conventions.

A file is contained in a directory (folder). Files within the samedirectory have unique names.

Every file and directory has a unique location in the file system,called a path.

I Absolute path:/Users/jackiebaek/Dropbox/Documents/hello.txt

I Relative path (if my current working directory is/Users/jackiebaek/Dropbox): Documents/hello.txt

Page 16: Introduction to Terminal - GitHub Pages · 2017-10-06 · Introduction to Terminal Computing in Optimization and Statistics: Lecture 1 Jackie Baek MIT January 10, 2017. ... (e.g.

Working with files

mkdir directory name: create a new directory.

$ mkdir new directory

touch file: create an empty file.rm file: delete a file (Careful! Can’t be undone!)

$ touch brand new file.txt

$ rm brand new file.txt

nano file: edit contents of a file (many other editors exist).

$ nano helloworld.txt

cat file: prints contents of a file.

$ cat helloworld.txt

Hello, World!

cp source target: copy.mv source target: move/rename.

$ cp helloworld.txt helloworld_copy.txt

$ mv helloworld.txt goodbyeworld.txt

Page 17: Introduction to Terminal - GitHub Pages · 2017-10-06 · Introduction to Terminal Computing in Optimization and Statistics: Lecture 1 Jackie Baek MIT January 10, 2017. ... (e.g.

Working with filesmkdir directory name: create a new directory.

$ mkdir new directory

touch file: create an empty file.rm file: delete a file (Careful! Can’t be undone!)

$ touch brand new file.txt

$ rm brand new file.txt

nano file: edit contents of a file (many other editors exist).

$ nano helloworld.txt

cat file: prints contents of a file.

$ cat helloworld.txt

Hello, World!

cp source target: copy.mv source target: move/rename.

$ cp helloworld.txt helloworld_copy.txt

$ mv helloworld.txt goodbyeworld.txt

Page 18: Introduction to Terminal - GitHub Pages · 2017-10-06 · Introduction to Terminal Computing in Optimization and Statistics: Lecture 1 Jackie Baek MIT January 10, 2017. ... (e.g.

Working with filesmkdir directory name: create a new directory.

$ mkdir new directory

touch file: create an empty file.rm file: delete a file (Careful! Can’t be undone!)

$ touch brand new file.txt

$ rm brand new file.txt

nano file: edit contents of a file (many other editors exist).

$ nano helloworld.txt

cat file: prints contents of a file.

$ cat helloworld.txt

Hello, World!

cp source target: copy.mv source target: move/rename.

$ cp helloworld.txt helloworld_copy.txt

$ mv helloworld.txt goodbyeworld.txt

Page 19: Introduction to Terminal - GitHub Pages · 2017-10-06 · Introduction to Terminal Computing in Optimization and Statistics: Lecture 1 Jackie Baek MIT January 10, 2017. ... (e.g.

Working with filesmkdir directory name: create a new directory.

$ mkdir new directory

touch file: create an empty file.rm file: delete a file (Careful! Can’t be undone!)

$ touch brand new file.txt

$ rm brand new file.txt

nano file: edit contents of a file (many other editors exist).

$ nano helloworld.txt

cat file: prints contents of a file.

$ cat helloworld.txt

Hello, World!

cp source target: copy.mv source target: move/rename.

$ cp helloworld.txt helloworld_copy.txt

$ mv helloworld.txt goodbyeworld.txt

Page 20: Introduction to Terminal - GitHub Pages · 2017-10-06 · Introduction to Terminal Computing in Optimization and Statistics: Lecture 1 Jackie Baek MIT January 10, 2017. ... (e.g.

Working with filesmkdir directory name: create a new directory.

$ mkdir new directory

touch file: create an empty file.rm file: delete a file (Careful! Can’t be undone!)

$ touch brand new file.txt

$ rm brand new file.txt

nano file: edit contents of a file (many other editors exist).

$ nano helloworld.txt

cat file: prints contents of a file.

$ cat helloworld.txt

Hello, World!

cp source target: copy.mv source target: move/rename.

$ cp helloworld.txt helloworld_copy.txt

$ mv helloworld.txt goodbyeworld.txt

Page 21: Introduction to Terminal - GitHub Pages · 2017-10-06 · Introduction to Terminal Computing in Optimization and Statistics: Lecture 1 Jackie Baek MIT January 10, 2017. ... (e.g.

Working with filesmkdir directory name: create a new directory.

$ mkdir new directory

touch file: create an empty file.rm file: delete a file (Careful! Can’t be undone!)

$ touch brand new file.txt

$ rm brand new file.txt

nano file: edit contents of a file (many other editors exist).

$ nano helloworld.txt

cat file: prints contents of a file.

$ cat helloworld.txt

Hello, World!

cp source target: copy.mv source target: move/rename.

$ cp helloworld.txt helloworld_copy.txt

$ mv helloworld.txt goodbyeworld.txt

Page 22: Introduction to Terminal - GitHub Pages · 2017-10-06 · Introduction to Terminal Computing in Optimization and Statistics: Lecture 1 Jackie Baek MIT January 10, 2017. ... (e.g.

File path shortcuts

. is current directory.

.. is parent directory.

I ../file.txt references a file named file.txt in the parentdirectory.

∼ is home.

I expands to /Users/<username> (or wherever home is on thatmachine).

I ∼/Documents → /Users/jackiebaek/Documents

I The command cd (without any arguments) takes you to ∼.

Page 23: Introduction to Terminal - GitHub Pages · 2017-10-06 · Introduction to Terminal Computing in Optimization and Statistics: Lecture 1 Jackie Baek MIT January 10, 2017. ... (e.g.

File path shortcuts

. is current directory.

.. is parent directory.

I ../file.txt references a file named file.txt in the parentdirectory.

∼ is home.

I expands to /Users/<username> (or wherever home is on thatmachine).

I ∼/Documents → /Users/jackiebaek/Documents

I The command cd (without any arguments) takes you to ∼.

Page 24: Introduction to Terminal - GitHub Pages · 2017-10-06 · Introduction to Terminal Computing in Optimization and Statistics: Lecture 1 Jackie Baek MIT January 10, 2017. ... (e.g.

Hidden Files

I Files that start with a dot (.) are called hidden files.

I Used for storing preferences, config, settings.

I Use ls -a to list all files.

$ ls

github_notes.md presentation scripts

$ ls -a

. .git github_notes.md scripts

.. .gitignore presentation

Page 25: Introduction to Terminal - GitHub Pages · 2017-10-06 · Introduction to Terminal Computing in Optimization and Statistics: Lecture 1 Jackie Baek MIT January 10, 2017. ... (e.g.

.bashrc / .bash profile

I There is a hidden file in ∼ directory called .bashrc or.bash profile.

I This file is a bash script that runs at the beginning of eachsession (i.e. when you open the terminal).

I This file can be used to set variables or to declare aliases.

I alias new command=command

$ alias athena="ssh [email protected]"

Page 26: Introduction to Terminal - GitHub Pages · 2017-10-06 · Introduction to Terminal Computing in Optimization and Statistics: Lecture 1 Jackie Baek MIT January 10, 2017. ... (e.g.

.bashrc / .bash profile

I There is a hidden file in ∼ directory called .bashrc or.bash profile.

I This file is a bash script that runs at the beginning of eachsession (i.e. when you open the terminal).

I This file can be used to set variables or to declare aliases.

I alias new command=command

$ alias athena="ssh [email protected]"

Page 27: Introduction to Terminal - GitHub Pages · 2017-10-06 · Introduction to Terminal Computing in Optimization and Statistics: Lecture 1 Jackie Baek MIT January 10, 2017. ... (e.g.

Redirection

> redirects output to a file, overwriting if file already exists.

$ ls > out.txt

>> redirects output to a file, appending if file already exists.

$ python fetch_data.py >> output.csv

< uses contents of file as STDIN (standard input) to thecommand.

$ python process_stuff.py < input.txt

Page 28: Introduction to Terminal - GitHub Pages · 2017-10-06 · Introduction to Terminal Computing in Optimization and Statistics: Lecture 1 Jackie Baek MIT January 10, 2017. ... (e.g.

Redirection

> redirects output to a file, overwriting if file already exists.

$ ls > out.txt

>> redirects output to a file, appending if file already exists.

$ python fetch_data.py >> output.csv

< uses contents of file as STDIN (standard input) to thecommand.

$ python process_stuff.py < input.txt

Page 29: Introduction to Terminal - GitHub Pages · 2017-10-06 · Introduction to Terminal Computing in Optimization and Statistics: Lecture 1 Jackie Baek MIT January 10, 2017. ... (e.g.

Secure Shell (SSH)

I Sometimes we need to work on a remote machine.I We need more computing power than just our local machine.I We need to access data from a client’s server.

I Can use SSH to securely access the terminal for the remotemachine.

$ ssh [email protected]

Password:

Welcome to Ubuntu 14.04.5 LTS

...

Last login: Tue Aug 30 10:11:49 2016 from howe-and-ser-...

baek@howe-and-ser-moving:~$

Use logout to exit SSH session.

Page 30: Introduction to Terminal - GitHub Pages · 2017-10-06 · Introduction to Terminal Computing in Optimization and Statistics: Lecture 1 Jackie Baek MIT January 10, 2017. ... (e.g.

Secure Shell (SSH)

I Sometimes we need to work on a remote machine.I We need more computing power than just our local machine.I We need to access data from a client’s server.

I Can use SSH to securely access the terminal for the remotemachine.

$ ssh [email protected]

Password:

Welcome to Ubuntu 14.04.5 LTS

...

Last login: Tue Aug 30 10:11:49 2016 from howe-and-ser-...

baek@howe-and-ser-moving:~$

Use logout to exit SSH session.

Page 31: Introduction to Terminal - GitHub Pages · 2017-10-06 · Introduction to Terminal Computing in Optimization and Statistics: Lecture 1 Jackie Baek MIT January 10, 2017. ... (e.g.

Secure Shell (SSH)

I Sometimes we need to work on a remote machine.I We need more computing power than just our local machine.I We need to access data from a client’s server.

I Can use SSH to securely access the terminal for the remotemachine.

$ ssh [email protected]

Password:

Welcome to Ubuntu 14.04.5 LTS

...

Last login: Tue Aug 30 10:11:49 2016 from howe-and-ser-...

baek@howe-and-ser-moving:~$

Use logout to exit SSH session.

Page 32: Introduction to Terminal - GitHub Pages · 2017-10-06 · Introduction to Terminal Computing in Optimization and Statistics: Lecture 1 Jackie Baek MIT January 10, 2017. ... (e.g.

Secure Shell (SSH)

I Sometimes we need to work on a remote machine.I We need more computing power than just our local machine.I We need to access data from a client’s server.

I Can use SSH to securely access the terminal for the remotemachine.

$ ssh [email protected]

Password:

Welcome to Ubuntu 14.04.5 LTS

...

Last login: Tue Aug 30 10:11:49 2016 from howe-and-ser-...

baek@howe-and-ser-moving:~$

Use logout to exit SSH session.

Page 33: Introduction to Terminal - GitHub Pages · 2017-10-06 · Introduction to Terminal Computing in Optimization and Statistics: Lecture 1 Jackie Baek MIT January 10, 2017. ... (e.g.

Secure Copy (scp)

Can transfer files between local and remote machines using the scpcommand on your local machine.

Move my file.txt from local machine to remote home directory.

$ scp my_file.txt [email protected]:~

Move remote file.txt from remote to local machine.

$ scp [email protected]:~/remote_file.txt .

Page 34: Introduction to Terminal - GitHub Pages · 2017-10-06 · Introduction to Terminal Computing in Optimization and Statistics: Lecture 1 Jackie Baek MIT January 10, 2017. ... (e.g.

Simple Pattern Matching (Globbing)

I Match [multiple] filenames with wildcard characters.

I Similar to regular expressions, but slightly different syntax.

Example:

$ ls

a1.txt a2.pdf apple.txt bar.pdf

$ echo a*

a1.txt a2.pdf apple.txt

$ echo a[0-9]*

a1.txt a2.pdf

$ echo *.pdf

a2.pdf bar.pdf

Page 35: Introduction to Terminal - GitHub Pages · 2017-10-06 · Introduction to Terminal Computing in Optimization and Statistics: Lecture 1 Jackie Baek MIT January 10, 2017. ... (e.g.

Simple Pattern Matching (Globbing)

I Match [multiple] filenames with wildcard characters.

I Similar to regular expressions, but slightly different syntax.

Example:

$ ls

a1.txt a2.pdf apple.txt bar.pdf

$ echo a*

a1.txt a2.pdf apple.txt

$ echo a[0-9]*

a1.txt a2.pdf

$ echo *.pdf

a2.pdf bar.pdf

Page 36: Introduction to Terminal - GitHub Pages · 2017-10-06 · Introduction to Terminal Computing in Optimization and Statistics: Lecture 1 Jackie Baek MIT January 10, 2017. ... (e.g.

Simple Pattern Matching (Globbing)

I Match [multiple] filenames with wildcard characters.

I Similar to regular expressions, but slightly different syntax.

Example:

$ ls

a1.txt a2.pdf apple.txt bar.pdf

$ echo a*

a1.txt a2.pdf apple.txt

$ echo a[0-9]*

a1.txt a2.pdf

$ echo *.pdf

a2.pdf bar.pdf

Page 37: Introduction to Terminal - GitHub Pages · 2017-10-06 · Introduction to Terminal Computing in Optimization and Statistics: Lecture 1 Jackie Baek MIT January 10, 2017. ... (e.g.

Simple Pattern Matching (Globbing)

I Match [multiple] filenames with wildcard characters.

I Similar to regular expressions, but slightly different syntax.

Example:

$ ls

a1.txt a2.pdf apple.txt bar.pdf

$ echo a*

a1.txt a2.pdf apple.txt

$ echo a[0-9]*

a1.txt a2.pdf

$ echo *.pdf

a2.pdf bar.pdf

Page 38: Introduction to Terminal - GitHub Pages · 2017-10-06 · Introduction to Terminal Computing in Optimization and Statistics: Lecture 1 Jackie Baek MIT January 10, 2017. ... (e.g.

Simple Pattern Matching (Globbing)

I Match [multiple] filenames with wildcard characters.

I Similar to regular expressions, but slightly different syntax.

Example:

$ ls

a1.txt a2.pdf apple.txt bar.pdf

$ echo a*

a1.txt a2.pdf apple.txt

$ echo a[0-9]*

a1.txt a2.pdf

$ echo *.pdf

a2.pdf bar.pdf

Page 39: Introduction to Terminal - GitHub Pages · 2017-10-06 · Introduction to Terminal Computing in Optimization and Statistics: Lecture 1 Jackie Baek MIT January 10, 2017. ... (e.g.

Simple Pattern Matching (Globbing)

Figure: Source: Wikipedia

Remove all files that end with .pyc

$ rm *.pyc

Copy all files that has ”dog” in its name to the animal/ directory.

$ cp *dog* animal/

Page 40: Introduction to Terminal - GitHub Pages · 2017-10-06 · Introduction to Terminal Computing in Optimization and Statistics: Lecture 1 Jackie Baek MIT January 10, 2017. ... (e.g.

Simple Pattern Matching (Globbing)

Figure: Source: Wikipedia

Remove all files that end with .pyc

$ rm *.pyc

Copy all files that has ”dog” in its name to the animal/ directory.

$ cp *dog* animal/

Page 41: Introduction to Terminal - GitHub Pages · 2017-10-06 · Introduction to Terminal Computing in Optimization and Statistics: Lecture 1 Jackie Baek MIT January 10, 2017. ... (e.g.

Simple Pattern Matching (Globbing)

Figure: Source: Wikipedia

Remove all files that end with .pyc

$ rm *.pyc

Copy all files that has ”dog” in its name to the animal/ directory.

$ cp *dog* animal/

Page 42: Introduction to Terminal - GitHub Pages · 2017-10-06 · Introduction to Terminal Computing in Optimization and Statistics: Lecture 1 Jackie Baek MIT January 10, 2017. ... (e.g.

How bash works

I Bash is a programming language.I Can set variables, use for loops, if statements, comments, etc.

I There are several special ”environment” variables (i.e.$PATH, $HOME, $USER, etc.) that many programs rely on.

Page 43: Introduction to Terminal - GitHub Pages · 2017-10-06 · Introduction to Terminal Computing in Optimization and Statistics: Lecture 1 Jackie Baek MIT January 10, 2017. ... (e.g.

How bash works

I Bash is a programming language.I Can set variables, use for loops, if statements, comments, etc.

I There are several special ”environment” variables (i.e.$PATH, $HOME, $USER, etc.) that many programs rely on.

Page 44: Introduction to Terminal - GitHub Pages · 2017-10-06 · Introduction to Terminal Computing in Optimization and Statistics: Lecture 1 Jackie Baek MIT January 10, 2017. ... (e.g.

How bash works

I Bash is a programming language.I Can set variables, use for loops, if statements, comments, etc.

I There are several special ”environment” variables (i.e.$PATH, $HOME, $USER, etc.) that many programs rely on.

Page 45: Introduction to Terminal - GitHub Pages · 2017-10-06 · Introduction to Terminal Computing in Optimization and Statistics: Lecture 1 Jackie Baek MIT January 10, 2017. ... (e.g.

How bash works con’tWhat happens when you type in a command, say pwd?

I Bash runs the program called pwd.I Where is this program?

I Usually under a directory called bin, which stands for binary.

I When you type in a command, bash looks for a program withthat name under the directories listed in the $PATHenvironment variable.

$ echo $PATH

/Users/jackiebaek/.local/bin:/Users/jackiebaek/.cabal/bin:/

Applications/ghc-7.10.3.app/Contents/bin:/usr/local/bin:

/usr/bin:/bin:/usr/sbin:/sbin:/usr/texbin

I $PATH contains is a list of directories separated by :

I Bash looks into each of these directories to look for theprogram pwd.

Page 46: Introduction to Terminal - GitHub Pages · 2017-10-06 · Introduction to Terminal Computing in Optimization and Statistics: Lecture 1 Jackie Baek MIT January 10, 2017. ... (e.g.

How bash works con’tWhat happens when you type in a command, say pwd?

I Bash runs the program called pwd.I Where is this program?

I Usually under a directory called bin, which stands for binary.

I When you type in a command, bash looks for a program withthat name under the directories listed in the $PATHenvironment variable.

$ echo $PATH

/Users/jackiebaek/.local/bin:/Users/jackiebaek/.cabal/bin:/

Applications/ghc-7.10.3.app/Contents/bin:/usr/local/bin:

/usr/bin:/bin:/usr/sbin:/sbin:/usr/texbin

I $PATH contains is a list of directories separated by :

I Bash looks into each of these directories to look for theprogram pwd.

Page 47: Introduction to Terminal - GitHub Pages · 2017-10-06 · Introduction to Terminal Computing in Optimization and Statistics: Lecture 1 Jackie Baek MIT January 10, 2017. ... (e.g.

How bash works con’tWhat happens when you type in a command, say pwd?

I Bash runs the program called pwd.I Where is this program?

I Usually under a directory called bin, which stands for binary.

I When you type in a command, bash looks for a program withthat name under the directories listed in the $PATHenvironment variable.

$ echo $PATH

/Users/jackiebaek/.local/bin:/Users/jackiebaek/.cabal/bin:/

Applications/ghc-7.10.3.app/Contents/bin:/usr/local/bin:

/usr/bin:/bin:/usr/sbin:/sbin:/usr/texbin

I $PATH contains is a list of directories separated by :

I Bash looks into each of these directories to look for theprogram pwd.

Page 48: Introduction to Terminal - GitHub Pages · 2017-10-06 · Introduction to Terminal Computing in Optimization and Statistics: Lecture 1 Jackie Baek MIT January 10, 2017. ... (e.g.

How bash works con’tWhat happens when you type in a command, say pwd?

I Bash runs the program called pwd.I Where is this program?

I Usually under a directory called bin, which stands for binary.

I When you type in a command, bash looks for a program withthat name under the directories listed in the $PATHenvironment variable.

$ echo $PATH

/Users/jackiebaek/.local/bin:/Users/jackiebaek/.cabal/bin:/

Applications/ghc-7.10.3.app/Contents/bin:/usr/local/bin:

/usr/bin:/bin:/usr/sbin:/sbin:/usr/texbin

I $PATH contains is a list of directories separated by :

I Bash looks into each of these directories to look for theprogram pwd.

Page 49: Introduction to Terminal - GitHub Pages · 2017-10-06 · Introduction to Terminal Computing in Optimization and Statistics: Lecture 1 Jackie Baek MIT January 10, 2017. ... (e.g.

Documentation

I To look up documentation for a particular command, use‘man command ‘. (man = manual)

$ man mkdir

NAME

mkdir -- make directories

SYNOPSIS

mkdir [-pv] [-m mode] directory_name ...

DESCRIPTION

The mkdir utility creates the directories named as operands

...

I d for down, u for up, q to quit.

I Commands can have required and/or optional arguments.

I Optional arguments usually come first, and are indicated by ahyphen (-). These are called flags.

Page 50: Introduction to Terminal - GitHub Pages · 2017-10-06 · Introduction to Terminal Computing in Optimization and Statistics: Lecture 1 Jackie Baek MIT January 10, 2017. ... (e.g.

Key Takeaways

I Basic commands: ls, cd, pwd, cat, cp, mv, rm, mkdir

I Google is your friend.

I So is tab for autocomplete, arrow keys for history.

I Be careful with rm.

I Getting comfortable with the terminal can be daunting atfirst, but it has the potential to greatly boost your efficiency!

Page 51: Introduction to Terminal - GitHub Pages · 2017-10-06 · Introduction to Terminal Computing in Optimization and Statistics: Lecture 1 Jackie Baek MIT January 10, 2017. ... (e.g.

Key Takeaways

I Basic commands: ls, cd, pwd, cat, cp, mv, rm, mkdir

I Google is your friend.

I So is tab for autocomplete, arrow keys for history.

I Be careful with rm.

I Getting comfortable with the terminal can be daunting atfirst, but it has the potential to greatly boost your efficiency!

Page 52: Introduction to Terminal - GitHub Pages · 2017-10-06 · Introduction to Terminal Computing in Optimization and Statistics: Lecture 1 Jackie Baek MIT January 10, 2017. ... (e.g.

Key Takeaways

I Basic commands: ls, cd, pwd, cat, cp, mv, rm, mkdir

I Google is your friend.

I So is tab for autocomplete, arrow keys for history.

I Be careful with rm.

I Getting comfortable with the terminal can be daunting atfirst, but it has the potential to greatly boost your efficiency!

Page 53: Introduction to Terminal - GitHub Pages · 2017-10-06 · Introduction to Terminal Computing in Optimization and Statistics: Lecture 1 Jackie Baek MIT January 10, 2017. ... (e.g.

Key Takeaways

I Basic commands: ls, cd, pwd, cat, cp, mv, rm, mkdir

I Google is your friend.

I So is tab for autocomplete, arrow keys for history.

I Be careful with rm.

I Getting comfortable with the terminal can be daunting atfirst, but it has the potential to greatly boost your efficiency!

Page 54: Introduction to Terminal - GitHub Pages · 2017-10-06 · Introduction to Terminal Computing in Optimization and Statistics: Lecture 1 Jackie Baek MIT January 10, 2017. ... (e.g.

Key Takeaways

I Basic commands: ls, cd, pwd, cat, cp, mv, rm, mkdir

I Google is your friend.

I So is tab for autocomplete, arrow keys for history.

I Be careful with rm.

I Getting comfortable with the terminal can be daunting atfirst, but it has the potential to greatly boost your efficiency!

Page 55: Introduction to Terminal - GitHub Pages · 2017-10-06 · Introduction to Terminal Computing in Optimization and Statistics: Lecture 1 Jackie Baek MIT January 10, 2017. ... (e.g.

Key Takeaways

I Basic commands: ls, cd, pwd, cat, cp, mv, rm, mkdir

I Google is your friend.

I So is tab for autocomplete, arrow keys for history.

I Be careful with rm.

I Getting comfortable with the terminal can be daunting atfirst, but it has the potential to greatly boost your efficiency!

Page 56: Introduction to Terminal - GitHub Pages · 2017-10-06 · Introduction to Terminal Computing in Optimization and Statistics: Lecture 1 Jackie Baek MIT January 10, 2017. ... (e.g.

Thank you!