welcome to linux & shell scripting small group how to learn how to code workshop small-group

29
Welcome to Linux & Shell Scripting Small Group How to learn how to Code Workshop http://onish.web.unc.edu/how-to-learn-how-to-code-l inux-small-group / Erin Osborne Nishimura 1

Upload: reynold-mckenzie

Post on 26-Dec-2015

222 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Welcome to Linux & Shell Scripting Small Group How to learn how to Code Workshop  small-group

1

Welcome to Linux & Shell ScriptingSmall Group

How to learn how to Code Workshop

http://onish.web.unc.edu/how-to-learn-how-to-code-linux-small-group

/

Erin Osborne Nishimura

Page 2: Welcome to Linux & Shell Scripting Small Group How to learn how to Code Workshop  small-group

2

Pop quiz!

Page 3: Welcome to Linux & Shell Scripting Small Group How to learn how to Code Workshop  small-group

3

Why should biologists learn to code?

• Power

• Efficiency

• Reproducibility

Page 4: Welcome to Linux & Shell Scripting Small Group How to learn how to Code Workshop  small-group

4

What are the barriers to learn to code?

• Where to begin?

• This feels awkward

• Sporadic use

• Hitting a wall/bug

• Finding help

• Cultural barriers

Page 5: Welcome to Linux & Shell Scripting Small Group How to learn how to Code Workshop  small-group

5

Where to begin?computing environments and languages

• Linux – an open-source operating system.

• bash – A command-writing language. The “language” of linux. Good for tasks, automated workflows, and general management.

• Python – A general purpose, high-level programming language. Highly readable and writable.• Perl – A general purpose, high-level programming language. Great with text files.• Javascript – a general purpose, high-level programming language. Specialized for web

applications, apps, commonly used in plugins (ImageJ).• Ruby -- A very high-level programming language.

• R – A high level programming language and software environment specialized for statistics and large data management.

• MATLAB – A computing environment and programming language. Good integration for image analysis. Costs money.

• MYSQL – Database organization

• Others?

OS

PR

OG

RA

MM

ING

LA

NG

UA

GE

SM

AT

H-y

LA

NG

UA

GE

SD

B

Page 6: Welcome to Linux & Shell Scripting Small Group How to learn how to Code Workshop  small-group

6

A HANDS-ON INTRO TO KILLDEVIL

How can I use some of these resources?

Page 7: Welcome to Linux & Shell Scripting Small Group How to learn how to Code Workshop  small-group

7

Killdevil is a high-performance computing environment

• Linux operating system• 1 login node• 774 compute nodes

– 48 – 96 GB memory per node.– 12 – 16 CPU’s cores per node.

• 2 large memory nodes (1 TB)• 12 Graphics Processors (GPUs)

nodes• File systems for storage

Page 8: Welcome to Linux & Shell Scripting Small Group How to learn how to Code Workshop  small-group

8

No seriously, what is Killdevil?

Page 9: Welcome to Linux & Shell Scripting Small Group How to learn how to Code Workshop  small-group

9

Getting onto Killdevil

• MAC OS & Linux machines:– Link to killdevil through

“Terminal”– Open “Terminal” (in

Applications -> Utilities)– Type this:ssh <yourOnyen>@killdevil.unc.edu

-- Add password when prompted

• PC– Open SSH Secure Shell

Client– Click on “Quick Connect”– Hostname =

killdevil.unc.edu– Username = <yourOnyen>– Port Number = 22– Add password when

prompted$ ssh [email protected]

Page 10: Welcome to Linux & Shell Scripting Small Group How to learn how to Code Workshop  small-group

10

WHAT IS LINUX?WHAT IS BASH?

Page 11: Welcome to Linux & Shell Scripting Small Group How to learn how to Code Workshop  small-group

11

Linux is a lifestyle

• Linux is an operating system• born out of UNIX• Linux comes in many flavors• Linux is the most prominent example of

the free, open-source movement• Linux embodies a philosophy of respect

for its users

Page 12: Welcome to Linux & Shell Scripting Small Group How to learn how to Code Workshop  small-group

12

bash is the shell for most linux distros

Page 13: Welcome to Linux & Shell Scripting Small Group How to learn how to Code Workshop  small-group

13

NAVIGATING THE LINUX ENVIRONMENT

Page 14: Welcome to Linux & Shell Scripting Small Group How to learn how to Code Workshop  small-group

14

Getting oriented

• Commands• Manuals

• Your first two commands:– whoami– Date

• Learn more about built-in utilities with man

$ whoamierinosb

$ dateThu Apr 9 13:24:09 EDT 2015

$ man whoami

Page 15: Welcome to Linux & Shell Scripting Small Group How to learn how to Code Workshop  small-group

15

Navigating – paths and directories

• pwd – Print Working Directory

• cd – Change Directorycd <directoryname>

• ls – List Contents

$ pwd

$ cd /nas02/home/

$ ls

Page 16: Welcome to Linux & Shell Scripting Small Group How to learn how to Code Workshop  small-group

16

Typical File Structures and Paths

Page 17: Welcome to Linux & Shell Scripting Small Group How to learn how to Code Workshop  small-group

17

The Killdevil file structure

• Directories and sub-directories are “folders”• Some important directories on Killdevilhttp

://help.unc.edu/help/getting-started-on-killdevil/#P63_6342

– ms/ mass storage – netscr/ scratch space– ~ home directory

• Making a new directorymkdir <directoryname>

• Removing a directoryrm –ri <directoryname>

$ mkdir 01_HTLHTCode$ cd 01_HTLTCode$ ls$ mkdir 01_week1$ cd 01_week1$ ls

Page 18: Welcome to Linux & Shell Scripting Small Group How to learn how to Code Workshop  small-group

18

Exercise #1

Page 19: Welcome to Linux & Shell Scripting Small Group How to learn how to Code Workshop  small-group

19

A few key tips and tricks

• Naming conventions– NO SPACES!

• Auto complete with TAB• Beginning of code line

– CTRL + A

• End of code line– CTRL + E

• What if I get stuck?– CTRL+C

• &#$%! Get me out of here!– Q– CTRL+C– CTRL+D– quit– logout– logoff– logout()– bye– quit()– q()– exit

• What if I need help?– man <command>– <command> -h– <command> --

help– <command>

• GOOGLE it!– Use language

name in search

Page 20: Welcome to Linux & Shell Scripting Small Group How to learn how to Code Workshop  small-group

20

Making and Removing files

• Making a file$ touch <filename>

• Removing a file$ rm –i <filename>

$ command [-OPTIONS] <requiredfiles> </required/path/>

$ cd$ ls$ cd 01_HTLTCode$ ls$ cd 01_week1$ ls$ touch 150615_NOTES.txt

Page 21: Welcome to Linux & Shell Scripting Small Group How to learn how to Code Workshop  small-group

21

Editing files

• nano, vi -- OK, but cumbersome– CTRL + X to exit– Type “y” to save

• SFTP client – better!– Cyberduck, Mozilla – SSH/SFTP

• Set it up, then drag and drop

$ nano 150615_NOTES.txt

Page 22: Welcome to Linux & Shell Scripting Small Group How to learn how to Code Workshop  small-group

22

Getting files onto and off of Kure

• sftp clients– Cyberduck, Mozilla – SSH/SFTP

• Set it up, then drag and drop

• scp

scp <filename> <onyen>@killdevil.unc.edu:/path/

• sftp, wget

Page 23: Welcome to Linux & Shell Scripting Small Group How to learn how to Code Workshop  small-group

23

Copying

• copying a file$ cp <filename> <newfilename>

OR

$ cp <oldfilename> </path/newfilename>OR

$ cp <filename> </path/>

• Copying a directory$ cp –r <dirname> </path/dirname>

OR$ cp –r <dirname> </path/>

Page 24: Welcome to Linux & Shell Scripting Small Group How to learn how to Code Workshop  small-group

24

moving/renaming

Renaming:$ mv <oldfilename> <newfilename>

Moving:$ mv <oldfilename> </path/newfilename>

OR$ mv <filename> </path/>

EXERCISE 3

Page 25: Welcome to Linux & Shell Scripting Small Group How to learn how to Code Workshop  small-group

25

Exploring files

• diff – difference between two files

• wc – count lines in files

• * is useful – wild card. Zero, one or more of any character.

Page 26: Welcome to Linux & Shell Scripting Small Group How to learn how to Code Workshop  small-group

26

bash

• Hello World

Page 27: Welcome to Linux & Shell Scripting Small Group How to learn how to Code Workshop  small-group

27

Capturing information -- variables

$ x=42$ echo x$ echo $x$ x=“onyen”$ echo $x$ echo ${x}$ echo “$x”$ echo ‘$x’

Page 28: Welcome to Linux & Shell Scripting Small Group How to learn how to Code Workshop  small-group

28

Capturing information -- arrays

$ starks=( “robb” “sansa” “arya” “bran” “rickon” )

$ echo $starks$ echo ${starks}$ echo ${starks[0]}$ echo ${starks[1]}$ echo ${starks[*]}$ starks[1]=“SANSA”$ echo ${starks[1]}

Page 29: Welcome to Linux & Shell Scripting Small Group How to learn how to Code Workshop  small-group

29

Don’t use all caps to name variables

• printenv shows environment variables