computing in engineering education interface! presents

17
Linux: Command Line Interface! October 2018 Computing in Engineering Education presents Bytes && Bites on

Upload: others

Post on 22-Oct-2021

1 views

Category:

Documents


0 download

TRANSCRIPT

Linux: Command Line Interface!

October 2018

Computing in Engineering Education presents

Bytes && Biteson

Presenting

Keshavamurthy Indireshkumar :

Computational Scientist

Judit Flo Gaya: Systems Administrator

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 more● 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 internet● Present everywhere!● Cloud Platforms● Research

Why Linux? Where is it used?● It is open source (free!) and highly efficient and reliable.

○ If you aren’t happy with some feature, you can change it! ○ You have full control on your computer/device with minimal space

● The top 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, which are much cheaper than their windows counterparts (bonus, azure’s 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 software; great OS for startups etc.

https://www.youtube.com/watch?v=a7RXsBQjGNM● MacOS is based on unix (see also:

https://www.lifewire.com/mac-os-x-is-not-linux-distribution-2204744)

What is Linux?● An open-source operating system

○ 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 build 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:

○ Debian■ Ubuntu■ LinuxMint

○ RedHat:■ Fedora■ CentOS

○ Slackware:■ Suse

The shell● Part of OS user interacts with. Shell

passes the user commands to the kernel (core of OS)

● Multiple shells: bash and tcsh are the most popular. Others: csh, mosh, 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 server.● 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 install MOBAXterm (https://mobaxterm.mobatek.net/)

Basic Commands 101● Which user am I using?:

>whoami● What shell are we in?:

>echo $SHELL● Where am I?

>pwd● How can I move from one directory to another:

>cd <directory_name>● Change to directory one level up..

>cd .. ● Change back to home directory ..

>cd ● List files ..

>ls● Listing, longer form with more details..

>ls -l● Create an “empty file”:

>touch test

● See what’s in the file:>less test>cat test

● Create a directory>mkdir dir1

● Move files (note file is moved into a directory)>mv test dir1>ls -l dir1

● Copy files>cp dir1/test .>ls -l>ls -l dir1

● Removing a directory>mkdir dir2>rmdir dir2>rmdir dir1

● Cannot remove dir1! Try the following:>rm -r dir1

Basic Commands 101 (Cont)● Moving a directory (moving is renaming!):

>mkdir dir1>mv dir1 dir2>mv dir2/dir1 /tmp/dir3

● What time is it>date

● What is this file?>file test>file dir1>file /usr/bin/bash>file

● Copying multiple files>touch test1 test2 test3>cp test* dir2

● What does a command do: >man cat >man less

Some fun with the terminal:>telnet towel.blinkenlights.nl>fortune

Something useful:>pwgen>factor 169>curl wttr.in/Boston>for i in {1..9}; do for j in $(seq 1 $i); do echo -ne $i×$j=$((i*j))\\t; done; echo;done

Basic Commands 101 (Cont)● Man is your friend! Ask for help!● What are flags/options on commands?

ls -l vs lsrm vs rm -r

● Multiple editors: pico, nano, vim, emacs, etc.

● We will concentrate on vim. Some fun references:○ https://www.openvim.com/○ https://vim-adventures.com/

● vi vs vim● vim has two modes: normal mode 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 :q!

Vimtutor

● Vim ships with its own tutorial. If you type “vimtutor” at 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 script) and run it.

● Now run vimtutor!

● Open a file and type this:#!/bin/bash#A primitive script to make directories and copy filesdaterm -rf dir1 dir2 dir3 dir4touch test1.txt test2.txt test3.txt test4.txtmkdir dir1 dir2 dir3 dir4#Do you see anything “wrong” below? If you do, correct it!mv test.txt dir1mv test20.txt dir2mv test3.txt dir3mv test4.txt dir4dateecho "All Done!"

● Run the script with:>bash files.sh

Bash Scripting

Intermediate and advanced Linux 1) Useful commands:

a) grep (egrep), cutb) pipe (|)c) redirection (>,>>,<)d) wildcardse) variables (explain $)f) du and df

g) ulimit2) Bash scripting again!

a) loops b) variablesc) create a script with a loop to do what

files-simple.sh does.

#!/bin/bash

for i in {1..4}dotouch test$i.txtmkdir dir$imv test$i.txt dir$idone

echo All done

Intermediate and advanced Linux (Cont)● Linux distributions (I’d like to do this before

so that they can be a bit independent with their own linux)a) centos, ubuntu, suse, etc.b) package managers (yum, apt)c) Installing software: fortune, cowsays,

sl, bastet● How to remote into your linux (and others)

a) Sshb) Scpc) Ssh keysd) Tunneling ssh

● File systems: xfs, ext3, ext4, fat, fstab● File structure : /etc, /root, /home● File permissions

● OS specific topicsa) processes (top, ps, ps -ef, kill (signals),

nohup, nice, etc.)b) Memory (free, swap)c) tar, gzip, file, ddd) export command (bash), setenv (csh, tcsh)e) Cronf) users (useradd, passwd, sudo)

g) Logs ● Network:

a) Ifconfig, ethtoolb) proc/netc) Nfs, mountd) Pinge) host/digf) iptables

Some URLsLinux tutorialshttps://people.ischool.berkeley.edu/~kevin/unix-tutorial/toc.htmlhttp://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 tutorialshttps://linuxconfig.org/bash-scripting-tutorial-for-beginners

https://ryanstutorials.net/bash-scripting-tutorial/

Online Linux Terminalshttp://www.webminal.org/

https://linuxcontainers.org/lxd/try-it/ https://itsfoss.com/online-linux-terminals/