Welcome to Linux & Shell Scripting Small Group How to learn how to Code Workshop small-group/ Erin Osborne Nishimura 1
Pop quiz! 2
Why should biologists learn to code? Power Efficiency Reproducibility 3
What are the barriers to learn to code? Where to begin? This feels awkward Sporadic use Hitting a wall/bug Finding help Cultural barriers 4
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? 5 OS PROGRAMMING LANGUAGES MATH-y LANGUAGES DB
A HANDS-ON INTRO TO KILLDEVIL How can I use some of these resources? 6
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 7
No seriously, what is Killdevil? 8
Getting onto Killdevil MAC OS & Linux machines: –Link to killdevil through “Terminal” –Open “Terminal” (in Applications -> Utilities) –Type this: -- Add password when prompted PC – Open SSH Secure Shell Client – Click on “Quick Connect” – Hostname = killdevil.unc.edu – Username = – Port Number = 22 – Add password when prompted $ ssh 9
WHAT IS LINUX? WHAT IS BASH? 10
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 11
bash is the shell for most linux distros 12
NAVIGATING THE LINUX ENVIRONMENT 13
Getting oriented Commands Manuals Your first two commands: – whoami – Date Learn more about built-in utilities with man $ whoami erinosb $ date Thu Apr 9 13:24:09 EDT $ man whoami
Navigating – paths and directories pwd – Print Working Directory cd – Change Directory cd ls – List Contents $ pwd $ cd /nas02/home/ $ ls 15
Typical File Structures and Paths 16
The Killdevil file structure Directories and sub-directories are “folders” Some important directories on Killdevil killdevil/#P63_ killdevil/#P63_6342 – ms/ mass storage – netscr/scratch space – ~home directory Making a new directory mkdir Removing a directory rm –ri $ mkdir 01_HTLHTCode $ cd 01_HTLTCode $ ls $ mkdir 01_week1 $ cd 01_week1 $ ls 17
Exercise #1 18
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 – -h – --help – GOOGLE it! – Use language name in search 19
Making and Removing files Making a file $ touch Removing a file $ rm –i $ command [-OPTIONS] $ cd $ ls $ cd 01_HTLTCode $ ls $ cd 01_week1 $ ls $ touch _NOTES.txt 20
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 21 $ nano _NOTES.txt
Getting files onto and off of Kure sftp clients –Cyberduck, Mozilla –SSH/SFTP Set it up, then drag and drop scp sftp, wget 22
Copying 23 copying a file $ cp OR $ cp OR $ cp Copying a directory $ cp –r OR $ cp –r
moving/renaming Renaming: $ mv Moving: $ mv OR $ mv EXERCISE 3 24
Exploring files diff – difference between two files wc – count lines in files * is useful – wild card. Zero, one or more of any character. 25
bash Hello World 26
Capturing information -- variables $ x=42 $ echo x $ echo $x $ x=“onyen” $ echo $x $ echo ${x} $ echo “$x” $ echo ‘$x’ 27
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]} 28
Don’t use all caps to name variables printenv shows environment variables 29