in Engineering Education presents Bytes && Bites on : Line Interface! October 2018 Presenting

Keshavamurthy Judit Flo Gaya: Indireshkumar : Systems Administrator Computational Scientist Why are you here?

● Never heard of linux, I love MacOS or Windows! ● Have heard but never used ● Have some idea and want to know a bit ● Convince me! ● I already used it and want to know more! ● Free food! Why Linux? Where is it used? ● Open Source ● SuperComputers/Clusters ● Backbone of the ● Present everywhere! ● Cloud Platforms ● Research Why Linux? Where is it used? ● It is open source (free!) and highly efficient and reliable. ○ If you aren’tag">t happy with some feature, you can change it! ○ You have full control on your /device with minimal space ● The 500 supercomputers in the world are running Linux as of one year ago (https://www.top500.org/statistics/sublist/) ● Linux servers form the backbone of internet (https://en.wikipedia.org/wiki/Usage_share_of_operating_systems#Market_share_by_category) ● It is present everywhere: smartTVs, powering your Android, Kindles, 3D printers ● Cloud platforms (AWS, Google cloud, even Azure) are mostly based on linux for building linux servers, are much cheaper than their windows counterparts (bonus, azure’ network is linux managed https://www.wired.com/2015/09/microsoft-using-linux-run-cloud/) ● Linux - essential for data science, machine learning, and deep learning. ● Cool home projects (including Internet of Things) with open ; great OS for startups etc. https://www.youtube.com/watch?v=a7RXsBQjGNM ● MacOS is based on (see also: https://www.lifewire.com/mac-os-x-is-not-linux-distribution-2204744) What is Linux? ● An open-source ○ Very similar to Unix, which is not open source (soap opera material). We use GNU Linux/Unix interchangeably ● An operating system (OS) is the software used for all interactions with the computer’s hardware. Other examples - Windows and Mac OS X(which itself is mostly unix-like). ● Unix (Linux) “philosophy” is to design simple and highly specialized programs that have been perfected through years so that they can be used together to a more complicated software. ● It’s the do-it-yourself philosophy to the max One Linux?

● https://en.wikipedia.org/wiki/List_of_Linux_distributions ● The main distros: ○ ■ LinuxMint ○ RedHat: ■ Fedora ■ CentOS ○ : ■ Suse The

● Part of OS interacts with. Shell passes the user commands to the kernel (core of OS) ● Multiple shells: and tcsh are the popular. Others: csh, , etc. We use bash in this tutorial. ● There are many ways to accomplish the same task, you can pick and choose which one you like the most. Linux Command Line Interface (CLI)

We will use an ssh tool to connect to a linux . ● If you have a Mac, you can use the terminal on the Mac and the native ssh capability.

There are small differences even within bash (shell) between the MacOS implementation (based on UNIX BSD) and the linux (GNU) version of it, but it will not be an issue for this workshop). ● If you have windows, please MOBAXterm (https://mobaxterm.mobatek.net/) Basic Commands 101

● Which user am I using?: ● See what’s in the : >whoami >less ● What shell are we in?: >cat test >echo $SHELL ● Create a ● Where am I? >mkdir dir1 >pwd ● files (note file is moved into a directory) ● How can I move from one directory to another: >mv test dir1 >cd >ls -l dir1 ● Change to directory one level up.. ● files >cd .. >cp dir1/test . ● Change back to home directory .. >ls -l >cd >ls -l dir1 ● List files .. ● Removing a directory >ls >mkdir dir2 ● Listing, longer form with more details.. >rmdir dir2 >ls -l >rmdir dir1 ● Create an “empty file”: ● Cannot remove dir1! Try the following: >touch test >rm -r dir1 Basic Commands 101 (Cont)

● Moving a directory (moving is renaming!): Some fun with the terminal: >mkdir dir1 >telnet towel.blinkenlights. >mv dir1 dir2 >fortune >mv dir2/dir1 /tmp/dir3 ● What is it Something useful: >date >pwgen ● What is this file? >factor 169 >file test >curl wttr.in/Boston >file dir1 >for i in {1..9}; do for in $( 1 $i); do - $i× >file /usr/bin/bash $j=$((i*j))\\t; done; echo;done >file ● Copying multiple files >touch test1 test2 test3 >cp test* dir2 ● What does a command do: >man >man Basic Commands 101 (Cont) ● Man is your friend! Ask for ! ● What are flags/options on commands? ls -l vs ls vs rm -r ● Multiple editors: , nano, , , etc. ● We will concentrate on vim. Some fun references: ○ https://www.openvim.com/ ○ https://vim-adventures.com/ ● vs vim ● vim has two modes: normal and insert mode ○ When you open a file with vim, you are in the normal mode. → Command mode ○ To change to insert mode: press i (lower case letter i) → Input text ○ Leave the insert mode: press the escape key esc ○ To leave a vim session without saving, go to normal mode and : press :! Vimtutor

● Vim ships with its own tutorial. If you “vimtutor” the cursor, you will be in the tutorial. ○ Work through lesson 1 in vimtutor ○ Once we are done with lesson 1, we will create a simple program (bash ) and run it.

● Now run vimtutor! Bash Scripting

● Open a file and type this: #!/bin/bash #A primitive script to directories and copy files date rm -rf dir1 dir2 dir3 dir4 touch test1.txt test2.txt test3.txt test4.txt mkdir dir1 dir2 dir3 dir4 #Do you see anything “wrong” below? If you do, correct it! mv test.txt dir1 mv test20.txt dir2 mv test3.txt dir3 mv test4.txt dir4 date echo "All Done!" ● Run the script with: >bash files.sh Intermediate and advanced Linux

1) Useful commands: #!/bin/bash a) (egrep), ) pipe (|) for i in {1..4} ) redirection (>,>>,<) do d) wildcards touch test$i.txt e) variables (explain $) mkdir $i f) and mv test$i.txt dir$i g) ulimit done 2) Bash scripting again! a) loops echo All done b) variables c) create a script with a loop to do what files-simple.sh does. Intermediate and advanced Linux (Cont) ● Linux distributions (I’d like to do this before ● OS specific topics so that they can be a bit independent with a) processes (top, , ps -ef, (signals), their own linux) , , etc.) a) centos, ubuntu, suse, etc. b) Memory (free, swap) b) package managers (yum, apt) c) , , file, c) Installing software: , cowsays, d) export command (bash), setenv (csh, tcsh) sl, bastet e) ● How to remote into your linux (and others) f) users (useradd, , ) a) Ssh g) Logs b) Scp ● Network: c) Ssh keys a) , d) Tunneling ssh b) proc/net ● File systems: , , ext4, fat, c) Nfs, ● File structure : /etc, /root, /home d) Ping ● File permissions e) / f) iptables Some URLs Linux tutorials https://people.ischool.berkeley.edu/~kevin/unix-tutorial/toc.html http://www.ee.surrey.ac.uk/Teaching/Unix/ https://ryanstutorials.net/linuxtutorial/ https://www.guru99.com/unix-linux-tutorial.html https://www.tutorialspoint.com/unix/

Bash tutorials https://linuxconfig.org/bash-scripting-tutorial-for-beginners https://ryanstutorials.net/bash-scripting-tutorial/

Online Linux Terminals http://www.webminal.org/ https://linuxcontainers.org/lxd/try-it/ https://itsfoss.com/online-linux-terminals/