cs197u: a hands on introduction to unix - umass amhersttian/197u/materials/lecture11.pdf · cs197u:...

31
U NIVERSITY OF M ASSACHUSETTS , A MHERST College of Information and Computer Sciences CS197U: A Hands on Introduction to Unix Lecture 11: WWW and Wrap up Tian Guo University of Massachusetts Amherst – CICS 1

Upload: others

Post on 23-Jun-2020

0 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: CS197U: A Hands on Introduction to Unix - UMass Amhersttian/197U/materials/lecture11.pdf · CS197U: A Hands on Introduction to Unix Lecture 11: WWW and Wrap up ... CICS 1. UNIVERSITY

UNIVERSITY OF MASSACHUSETTS, AMHERST • College of Information and Computer Sciences

CS197U: A Hands on Introduction to Unix

Lecture 11: WWW and Wrap up

Tian Guo University of Massachusetts Amherst – CICS

1

Page 2: CS197U: A Hands on Introduction to Unix - UMass Amhersttian/197U/materials/lecture11.pdf · CS197U: A Hands on Introduction to Unix Lecture 11: WWW and Wrap up ... CICS 1. UNIVERSITY

UNIVERSITY OF MASSACHUSETTS, AMHERST • College of Information and Computer Sciences

• Assignment 4 was graded and scores on Moodle

• Assignment 5 was due and you can stop the cron jobs after 10 emails ‣ I will grade it this weekend. And those who have more than 45

(including attendance) will have flexibility for the remaining assignments.

• Assignment 6 is due Oct 29; please start early!

• Assignment 7 is going to post soon!

Reminders

2

Page 3: CS197U: A Hands on Introduction to Unix - UMass Amhersttian/197U/materials/lecture11.pdf · CS197U: A Hands on Introduction to Unix Lecture 11: WWW and Wrap up ... CICS 1. UNIVERSITY

UNIVERSITY OF MASSACHUSETTS, AMHERST • College of Information and Computer Sciences

• How to access to your website? ‣ http://www-edlab.cs.umass.edu/~USERNAME/index.html

• How to modify your website? ‣ Default path is under your home directory: ~/public_html ‣ By default, index.html already exists there

• What else could you put inside ~/public_html? ‣ Everything you want others to see

Goal: Set up your personal website (EdLab)

3

Page 4: CS197U: A Hands on Introduction to Unix - UMass Amhersttian/197U/materials/lecture11.pdf · CS197U: A Hands on Introduction to Unix Lecture 11: WWW and Wrap up ... CICS 1. UNIVERSITY

UNIVERSITY OF MASSACHUSETTS, AMHERST • College of Information and Computer Sciences

• Copy through command line (Mac/Linux) ‣ scp filename [email protected]:~/public_html

• Copy using WinSCP (Windows) ‣ Connect to elnux4.cs.umass.edu and drag the file

• How do others see it? ‣ Assuming we have a new file “empty.html” ‣ URL: http://www-edlab.cs.umass.edu/~USERNAME/empty.html

Putting stuffs into public_html

4

Page 5: CS197U: A Hands on Introduction to Unix - UMass Amhersttian/197U/materials/lecture11.pdf · CS197U: A Hands on Introduction to Unix Lecture 11: WWW and Wrap up ... CICS 1. UNIVERSITY

UNIVERSITY OF MASSACHUSETTS, AMHERST • College of Information and Computer Sciences

• What permissions to set for files in public_html? ‣ What happens if empty.html is set to 600?

‣ Make it visible: set to 755 or 644 - Chmod 755 empty.html Or Chmod 644 empty.html

Control the permission

5

Page 6: CS197U: A Hands on Introduction to Unix - UMass Amhersttian/197U/materials/lecture11.pdf · CS197U: A Hands on Introduction to Unix Lecture 11: WWW and Wrap up ... CICS 1. UNIVERSITY

UNIVERSITY OF MASSACHUSETTS, AMHERST • College of Information and Computer Sciences

• A markup language of tags that can create a webpage in couple lines

<html>

<body>

<!- - This is a comment - - >

This is a webpage.

</body>

</html>

HTML: HyperText Markup Language

6

Page 7: CS197U: A Hands on Introduction to Unix - UMass Amhersttian/197U/materials/lecture11.pdf · CS197U: A Hands on Introduction to Unix Lecture 11: WWW and Wrap up ... CICS 1. UNIVERSITY

UNIVERSITY OF MASSACHUSETTS, AMHERST • College of Information and Computer Sciences

• Paired Tags: Opening and closing tag ‣ Headings of different sizes: h1~h6: <h1> Heading1 </h1> ‣ Start paragraph: <p> A Paragraph </p> ‣ Hyperlink: <a href=“http://www.google.com/“>link_to_Google</a>

- Link to your email: replace “http://URL” by “mailto:[email protected]

• Unpaired Tags ‣ Reference Image: <img src=“myPhoto.jpg" width=“60" height=“90“/> ‣ Line Breaker: <br> ‣ Horizontal line: <hr>

Tags

7

Page 8: CS197U: A Hands on Introduction to Unix - UMass Amhersttian/197U/materials/lecture11.pdf · CS197U: A Hands on Introduction to Unix Lecture 11: WWW and Wrap up ... CICS 1. UNIVERSITY

UNIVERSITY OF MASSACHUSETTS, AMHERST • College of Information and Computer Sciences

• Code

• Result

Heading Tags

8

Page 9: CS197U: A Hands on Introduction to Unix - UMass Amhersttian/197U/materials/lecture11.pdf · CS197U: A Hands on Introduction to Unix Lecture 11: WWW and Wrap up ... CICS 1. UNIVERSITY

UNIVERSITY OF MASSACHUSETTS, AMHERST • College of Information and Computer Sciences

• Code

• Result

Paragraph Tag

9

Page 10: CS197U: A Hands on Introduction to Unix - UMass Amhersttian/197U/materials/lecture11.pdf · CS197U: A Hands on Introduction to Unix Lecture 11: WWW and Wrap up ... CICS 1. UNIVERSITY

UNIVERSITY OF MASSACHUSETTS, AMHERST • College of Information and Computer Sciences

• Code

• Result

Hyperlink

10

Page 11: CS197U: A Hands on Introduction to Unix - UMass Amhersttian/197U/materials/lecture11.pdf · CS197U: A Hands on Introduction to Unix Lecture 11: WWW and Wrap up ... CICS 1. UNIVERSITY

UNIVERSITY OF MASSACHUSETTS, AMHERST • College of Information and Computer Sciences

• Code

• Result

Image Tag

11

Page 12: CS197U: A Hands on Introduction to Unix - UMass Amhersttian/197U/materials/lecture11.pdf · CS197U: A Hands on Introduction to Unix Lecture 11: WWW and Wrap up ... CICS 1. UNIVERSITY

UNIVERSITY OF MASSACHUSETTS, AMHERST • College of Information and Computer Sciences

• Code

• Results

br Tag

12

Page 13: CS197U: A Hands on Introduction to Unix - UMass Amhersttian/197U/materials/lecture11.pdf · CS197U: A Hands on Introduction to Unix Lecture 11: WWW and Wrap up ... CICS 1. UNIVERSITY

UNIVERSITY OF MASSACHUSETTS, AMHERST • College of Information and Computer Sciences

• Code

• Result

hr Tag

13

Page 14: CS197U: A Hands on Introduction to Unix - UMass Amhersttian/197U/materials/lecture11.pdf · CS197U: A Hands on Introduction to Unix Lecture 11: WWW and Wrap up ... CICS 1. UNIVERSITY

UNIVERSITY OF MASSACHUSETTS, AMHERST • College of Information and Computer Sciences

• Code Academy: HTML & CSS ‣ https://www.codecademy.com/tracks/web

• w3school ‣ http://www.w3schools.com/

More Resources

14

Page 15: CS197U: A Hands on Introduction to Unix - UMass Amhersttian/197U/materials/lecture11.pdf · CS197U: A Hands on Introduction to Unix Lecture 11: WWW and Wrap up ... CICS 1. UNIVERSITY

UNIVERSITY OF MASSACHUSETTS, AMHERST • College of Information and Computer Sciences

• xargs: commonly used in pipe to convert multiple lines into single-line argument list

• Example 1: Check out xargs by itself ‣ ls -1 data/ | xargs ‣ Converts output into one line

‣ Why is it useful?

The last but very useful command

15

elnux4 tian) > ls -1 data/ | xargs data-1.txt data-2.txt data-3.txt

Page 16: CS197U: A Hands on Introduction to Unix - UMass Amhersttian/197U/materials/lecture11.pdf · CS197U: A Hands on Introduction to Unix Lecture 11: WWW and Wrap up ... CICS 1. UNIVERSITY

UNIVERSITY OF MASSACHUSETTS, AMHERST • College of Information and Computer Sciences

• Combine it with find: filters out a list of finds and perform some actions

• Do things for all python files (including subdirectories) ‣ find . -name “*.py” | xargs wc -l # Counts the lines of the code ‣ find . -name “*.py” | xargs grep “import” # Looks for import package

The last but very useful command

16

Page 17: CS197U: A Hands on Introduction to Unix - UMass Amhersttian/197U/materials/lecture11.pdf · CS197U: A Hands on Introduction to Unix Lecture 11: WWW and Wrap up ... CICS 1. UNIVERSITY

UNIVERSITY OF MASSACHUSETTS, AMHERST • College of Information and Computer Sciences

• Run command on different files without for loop ‣ The for loop way

‣ Get the file name; and invoke command for each file ‣ xargs way: ls -1 data/ | xargs -I {} awk -f avg.awk data/{}

The last but very useful command

17

for file in data/* do echo $file awk -f avg.awk $file done

Page 18: CS197U: A Hands on Introduction to Unix - UMass Amhersttian/197U/materials/lecture11.pdf · CS197U: A Hands on Introduction to Unix Lecture 11: WWW and Wrap up ... CICS 1. UNIVERSITY

UNIVERSITY OF MASSACHUSETTS, AMHERST • College of Information and Computer Sciences

• Using the command line:

• Reading files

• Editing files

cd mv rmmkdir pwd ls

head tail catless more grep

vim awk sed

What we’ve learned

18

Page 19: CS197U: A Hands on Introduction to Unix - UMass Amhersttian/197U/materials/lecture11.pdf · CS197U: A Hands on Introduction to Unix Lecture 11: WWW and Wrap up ... CICS 1. UNIVERSITY

UNIVERSITY OF MASSACHUSETTS, AMHERST • College of Information and Computer Sciences

• Using pipes

• Using output redirection to save output to a file

• Some special symbols

grep  “Romeo”  file.txt  |  head  -­‐n  100  |  tail  -­‐n  10

grep  “Romeo”  file.txt  >  RandJ.txt  grep  “Juliet”  file.txt  >>  RandJ.txt

../ ./ * &

parent directory

current directory

match all files

run cmd in background

and...

19

Page 20: CS197U: A Hands on Introduction to Unix - UMass Amhersttian/197U/materials/lecture11.pdf · CS197U: A Hands on Introduction to Unix Lecture 11: WWW and Wrap up ... CICS 1. UNIVERSITY

UNIVERSITY OF MASSACHUSETTS, AMHERST • College of Information and Computer Sciences

• OS enforces file permissions for user, group, and world

• chmod command is used to change permissions

• Root user has absolute power, or use sudo

• Package managers can help find and install software

elnux7>  ls  -­‐l  -­‐rwxr-­‐xr-­‐x    1  twood    grad      97  Feb  21  11:33  script.sh  -­‐rw-­‐r-­‐-­‐r-­‐-­‐    1  twood    grad    298  Feb  21  11:22  data.txt

sudo  apt-­‐get  install  firefox

Important concepts

20

Page 21: CS197U: A Hands on Introduction to Unix - UMass Amhersttian/197U/materials/lecture11.pdf · CS197U: A Hands on Introduction to Unix Lecture 11: WWW and Wrap up ... CICS 1. UNIVERSITY

About the filesystem

• The filesystem is hierarchical• Directories can contain files or other directories

• / is the root directory, where the hierarchy begins

• Other important directories to remember:

/bin/ - executable files

/sbin/ - privileged executables

/dev/ - devices

/etc - system configuration

/home/ - user home directories

/lib/ - libraries

/opt/ - third-party software

/sys/ - Kernel, device drivers, etc

/usr/ - Other OS programs and data

/var/ - Logs, databases, rapidly-changing file

21

Page 22: CS197U: A Hands on Introduction to Unix - UMass Amhersttian/197U/materials/lecture11.pdf · CS197U: A Hands on Introduction to Unix Lecture 11: WWW and Wrap up ... CICS 1. UNIVERSITY

UNIVERSITY OF MASSACHUSETTS, AMHERST • College of Information and Computer Sciences

• ps and top to learn about running processes

• Lots of log and system files with OS information

elnux5>  ps      PID  TTY                    TIME  CMD  17786  pts/0    00:00:00  tcsh  17830  pts/0    00:00:00  bash  17832  pts/0    00:00:00  top  17833  pts/0    00:00:00  ps

tail  /var/log/messages  cat  /proc/cpuinfo

How to get system info

22

Page 23: CS197U: A Hands on Introduction to Unix - UMass Amhersttian/197U/materials/lecture11.pdf · CS197U: A Hands on Introduction to Unix Lecture 11: WWW and Wrap up ... CICS 1. UNIVERSITY

Programming and scripting

• C / C++ tools

• Python,  perl,  ruby,  and many more  

• Shell scripting

gcc c compiler

g++ c++ compiler

gdb debugger

make build automator

#  Command  line  arguments:  dir=$1  

if  [  -­‐d  “$dir”  ]  then  echo  “Reading  files  in  $d”  else  echo  “Not  a  directory”  exit  fi  

for  f  in  $dir/*.csv  do      awk  -­‐F  “,”  ‘{print  $3+$4}’  $f  done

23

Page 24: CS197U: A Hands on Introduction to Unix - UMass Amhersttian/197U/materials/lecture11.pdf · CS197U: A Hands on Introduction to Unix Lecture 11: WWW and Wrap up ... CICS 1. UNIVERSITY

UNIVERSITY OF MASSACHUSETTS, AMHERST • College of Information and Computer Sciences

• Awk is a scripting language for processing structured data• Log files, experimental results, etc

• Can use on the command line or write in a file:

• Very powerful!

• Often used with grep and pipe• <COMMAND> | grep <KEYWORD> | head –n 10 | awk –F”:” ‘{print $n}’

awk  -­‐F  “,”        '{print  $2}'      data.txt

awk  -­‐F  “,”        -­‐f  script.awk      data.txt

awk

24

Page 25: CS197U: A Hands on Introduction to Unix - UMass Amhersttian/197U/materials/lecture11.pdf · CS197U: A Hands on Introduction to Unix Lecture 11: WWW and Wrap up ... CICS 1. UNIVERSITY

UNIVERSITY OF MASSACHUSETTS, AMHERST • College of Information and Computer Sciences

• Version control systems are used to store and track source code• Subversion is an open source version

• Important concepts:• Repository - stores history of all files being tracked

• You never edit these files directly

• Local copy - “check out” files from repository to edit them • Modify the files as you like

• Update - updates your local copies • Detects if another user modified the same file• Attempts to merge changes (only works for text files)

• Commit - sends your versions of the files to the repository • Will only update repository if there are no conflicts

Version Control

25

Page 26: CS197U: A Hands on Introduction to Unix - UMass Amhersttian/197U/materials/lecture11.pdf · CS197U: A Hands on Introduction to Unix Lecture 11: WWW and Wrap up ... CICS 1. UNIVERSITY

UNIVERSITY OF MASSACHUSETTS, AMHERST • College of Information and Computer Sciences

• tar command creates one file that is an archive of other files

• also allows you to compress files

• scp command allows you to copy files to or from a remote machine  

• rsync synchronizes files and directory

Working with Files

26

Page 27: CS197U: A Hands on Introduction to Unix - UMass Amhersttian/197U/materials/lecture11.pdf · CS197U: A Hands on Introduction to Unix Lecture 11: WWW and Wrap up ... CICS 1. UNIVERSITY

UNIVERSITY OF MASSACHUSETTS, AMHERST • College of Information and Computer Sciences

• screen  : detach/attach to terminal sessions  • Useful for running long processes

• ctrl-­‐z : Suspend a job  

• jobs  :  Provides status of suspended jobs  

• bg  : Runs jobs in the background  

• fg  : Runs jobs in the foreground  

• nohup:  run jobs in detached manner from terminal  

• cron:  schedule reoccurring jobs  

• nice and renice allow you to control process priority

Managing Processes

27

Page 28: CS197U: A Hands on Introduction to Unix - UMass Amhersttian/197U/materials/lecture11.pdf · CS197U: A Hands on Introduction to Unix Lecture 11: WWW and Wrap up ... CICS 1. UNIVERSITY

UNIVERSITY OF MASSACHUSETTS, AMHERST • College of Information and Computer Sciences

Your network

28

ifconfig/if  up/if  down Information about interfaces

iwconfig/iwlist Wireless connection/association

dhclient Getting an IP address from DHCP server

ping Checking out a remote host

host Resolve the name/IP address of a site

traceroute Tracking a packet’s end-to-end path/delay

Page 29: CS197U: A Hands on Introduction to Unix - UMass Amhersttian/197U/materials/lecture11.pdf · CS197U: A Hands on Introduction to Unix Lecture 11: WWW and Wrap up ... CICS 1. UNIVERSITY

UNIVERSITY OF MASSACHUSETTS, AMHERST • College of Information and Computer Sciences

Network security and traffic monitoring

29

arp Address resolution protocol (IP vs. MAC)

ifstat   Real time bandwidth monitoring on all interfaces

iftop Monitoring details of specific interface

ftp/scp (Un)secure file transport

wireshark Packet sniffing

Page 30: CS197U: A Hands on Introduction to Unix - UMass Amhersttian/197U/materials/lecture11.pdf · CS197U: A Hands on Introduction to Unix Lecture 11: WWW and Wrap up ... CICS 1. UNIVERSITY

UNIVERSITY OF MASSACHUSETTS, AMHERST • College of Information and Computer Sciences

• find  - prints the path to a file  

• locate – finds system files  

• whereis/which - locate a binary file

• diff - compares two files  

• sort – sorts a file alphabetically or numerically

• uniq - removes identical adjacent lines

• ‘cd  -­‐’    - moves to the last directory you were in  

• export – declare and export variables  

• alias - creates a shortcut to a command for the bash shell

Random useful commands

30

Page 31: CS197U: A Hands on Introduction to Unix - UMass Amhersttian/197U/materials/lecture11.pdf · CS197U: A Hands on Introduction to Unix Lecture 11: WWW and Wrap up ... CICS 1. UNIVERSITY

UNIVERSITY OF MASSACHUSETTS, AMHERST • College of Information and Computer Sciences

• 377 Operating Systems• Learn how the Linux kernel works

• 453 Networking and 491G Networking Lab• Networking protocols, routing configuration

• 365 Digital Forensics• Learn about security and low level forensics

Take some more classes

31