comp 104: intro to unix week 3. review of last week unix file system structure file types and access...

63
COMP 104: Intro to Unix Week 3

Upload: osborne-wood

Post on 17-Dec-2015

217 views

Category:

Documents


1 download

TRANSCRIPT

Page 1: COMP 104: Intro to Unix Week 3. Review of Last Week Unix file system structure File types and access permissions Create and use directories and files

COMP 104: Intro to Unix

Week 3

Page 2: COMP 104: Intro to Unix Week 3. Review of Last Week Unix file system structure File types and access permissions Create and use directories and files

Review of Last Week

Unix file system structure File types and access permissions Create and use directories and files Edit files with vi Use the following Unix commands:

cd, chmod, cp, id, mkdir, mv, pwd, rm, rmdir, touch, umask, vi

Page 3: COMP 104: Intro to Unix Week 3. Review of Last Week Unix file system structure File types and access permissions Create and use directories and files

Agenda – Activity 1 Introduction to Unix Processes

Foreground Process Background Process Running Processes in the background

& character Suspending Processes

^Z special key Displaying suspended jobs

jobs command

Page 4: COMP 104: Intro to Unix Week 3. Review of Last Week Unix file system structure File types and access permissions Create and use directories and files

Agenda – Activity 1 Continued

Displaying status of processes ps command

Killing Processes kill, and kill –9 command

In Class Exercise

Page 5: COMP 104: Intro to Unix Week 3. Review of Last Week Unix file system structure File types and access permissions Create and use directories and files

Agenda – Activity 1 Continued

Standard Input and Output Redirection and Pipes

>, >>, <, | Common Unix Filters

grep, look, sort, spell, uniq, wc Demonstration of Unix Filters,

Redirection, and Pipes In Class Assignment

Page 6: COMP 104: Intro to Unix Week 3. Review of Last Week Unix file system structure File types and access permissions Create and use directories and files

Agenda – Activity 2

How to use WinSCP2 to transfer files from your PC to einstein.

Unix Utilities ftp telnet pine elm

Demonstration of Unix Utilities Break (10 minutes)

Page 7: COMP 104: Intro to Unix Week 3. Review of Last Week Unix file system structure File types and access permissions Create and use directories and files

Agenda – Activity 3

Review for Today’s Final Exam

Page 8: COMP 104: Intro to Unix Week 3. Review of Last Week Unix file system structure File types and access permissions Create and use directories and files

Agenda – Activity 4

Course Evaluation Break (10 minutes)

Page 9: COMP 104: Intro to Unix Week 3. Review of Last Week Unix file system structure File types and access permissions Create and use directories and files

Agenda – Activity 5

Take the Final Exam!

Page 10: COMP 104: Intro to Unix Week 3. Review of Last Week Unix file system structure File types and access permissions Create and use directories and files

Activity 1

Page 11: COMP 104: Intro to Unix Week 3. Review of Last Week Unix file system structure File types and access permissions Create and use directories and files

UNIX Processes

A PROCESS is a program that is executing.

Processes have Input and Output

There are two types of Processes Foreground Processes Background Processes

Page 12: COMP 104: Intro to Unix Week 3. Review of Last Week Unix file system structure File types and access permissions Create and use directories and files

Foreground Process

When running a FOREGROUND process, the shell waits for the program to finish

When the process is finished, you will be returned to the command prompt/export/home/morris07>

Page 13: COMP 104: Intro to Unix Week 3. Review of Last Week Unix file system structure File types and access permissions Create and use directories and files

Background Process

When running a BACKGROUND process, the shell starts the process, then leaves

This allows you to execute other commands at the command prompt

NOTE: Handy for programs that take a long time to run and do not need to run interactively.

Page 14: COMP 104: Intro to Unix Week 3. Review of Last Week Unix file system structure File types and access permissions Create and use directories and files

Running Processes in Background

Type an ampersand (&) after the command to run it in the background

> find . –name java > javaLocations.txt &

Page 15: COMP 104: Intro to Unix Week 3. Review of Last Week Unix file system structure File types and access permissions Create and use directories and files

Suspending Processes

You can SUSPEND a process by typing ^Z

This will pause the process temporarily. The process can be resumed in the Foreground or moved to the Background:

/export/home/morris07> fg [jobid]/export/home/morris07> bg [jobid]

Page 16: COMP 104: Intro to Unix Week 3. Review of Last Week Unix file system structure File types and access permissions Create and use directories and files

Displaying List of Suspended Jobs

/export/home/morris07> jobs…

[1] Stopped vi document[2] Stopped elm

-l option gives more information

Page 17: COMP 104: Intro to Unix Week 3. Review of Last Week Unix file system structure File types and access permissions Create and use directories and files

Displaying Status of Processes

Use ps to report the status of a process

/export/home/morris07>ps… PID TTY TIME CMD19834 pts/7 0:05 ksh19954 pts/7 0:04 ps

Page 18: COMP 104: Intro to Unix Week 3. Review of Last Week Unix file system structure File types and access permissions Create and use directories and files

Killing a Process

Use kill to terminate a process running in the background

/export/home/morris07>kill {process id}

This sends a signal to the process to end.

Page 19: COMP 104: Intro to Unix Week 3. Review of Last Week Unix file system structure File types and access permissions Create and use directories and files

That Process Won’t Die!!

The kill command waits for the process to perform cleanup: write to files, close files,etc.

If the process will not end, use the ‘-9’ or ‘-KILL’ to kill the process immediately

> kill –9 19954> kill –KILL 19954

Page 20: COMP 104: Intro to Unix Week 3. Review of Last Week Unix file system structure File types and access permissions Create and use directories and files

In Class Exercise1. Start vi /etc/motd2. In Command Mode type ^Z3. Type jobs -l to see any suspended jobs4. Type fg to bring last suspended job to

foreground.5. In Command Mode type ^Z6. Type jobs -l to see any suspended jobs7. Type kill {Process ID} to kill the process8. Type ps to get current list of processes9. If the process is still running, type ‘kill –9

{Process ID}10. Type ps to get current list of processes

Page 21: COMP 104: Intro to Unix Week 3. Review of Last Week Unix file system structure File types and access permissions Create and use directories and files

Question/Answer Session

Page 22: COMP 104: Intro to Unix Week 3. Review of Last Week Unix file system structure File types and access permissions Create and use directories and files

Standard Input and Output

command terminal standard output

standard inputcommandkeyboard

Page 23: COMP 104: Intro to Unix Week 3. Review of Last Week Unix file system structure File types and access permissions Create and use directories and files

Redirection and Pipes

Redirecting Standard Output to a File with: ‘>’, ‘>>’

ls –al > mylist (creates or overwrites file)

ls –al >> mylist (appends or creates file)

command terminal standard output

command file redirected output

Page 24: COMP 104: Intro to Unix Week 3. Review of Last Week Unix file system structure File types and access permissions Create and use directories and files

Redirection and Pipes

Redirecting Standard Output to a Command with: ‘|’

ls –al | more (passes output to command)

command terminal standard output

command redirected outputcommand

Page 25: COMP 104: Intro to Unix Week 3. Review of Last Week Unix file system structure File types and access permissions Create and use directories and files

Redirection and Pipes

Redirecting Standard Input from a File with: ‘<’

cat < file (passes file to command)

standard input

redirected inputcommand

commandkeyboard

file

Page 26: COMP 104: Intro to Unix Week 3. Review of Last Week Unix file system structure File types and access permissions Create and use directories and files

Filters

A FILTER is any program that reads from Standard Input and writes to Standard Output.

grepuniqlookspellsortwc

Page 27: COMP 104: Intro to Unix Week 3. Review of Last Week Unix file system structure File types and access permissions Create and use directories and files

Filters: grep

The grep command searches for the pattern specified and writes these lines to Standard Output.

grep [-cilnvw] pattern [file…]

> grep ‘Easy’ assignments.txt

Page 28: COMP 104: Intro to Unix Week 3. Review of Last Week Unix file system structure File types and access permissions Create and use directories and files

Demonstration - grep

Page 29: COMP 104: Intro to Unix Week 3. Review of Last Week Unix file system structure File types and access permissions Create and use directories and files

Filters: uniq

The uniq command examines data, looking for consecutive, duplicate lines.

uniq [-cdu] [infile [outfile]] uniq –d , retains one copy of all lines that are

duplicated uniq –u, retains only those lines that are not

duplicated. uniq –c, counts how many times each line is found.

> uniq document.txt

Page 30: COMP 104: Intro to Unix Week 3. Review of Last Week Unix file system structure File types and access permissions Create and use directories and files

Filters: look

The look command searches data in alphabetical order and will find lines that begin with a specified pattern (alphabetical characters only).

look [-df] pattern [file…]

>look Amer* Access the dictionary of correctly spelled words.

• Look is not really a filter and cannot be used within a pipeline. • File must be pre-sort file with –dfu options. I.e dictionary, fold,

unique.

Page 31: COMP 104: Intro to Unix Week 3. Review of Last Week Unix file system structure File types and access permissions Create and use directories and files

Filters: look

Page 32: COMP 104: Intro to Unix Week 3. Review of Last Week Unix file system structure File types and access permissions Create and use directories and files

Filters: spell

The spell command will read data and generate a list of all words that look as if they are misspelled. This is a very primitive spell checker.

spell [file…]

>spell document.txt

Page 33: COMP 104: Intro to Unix Week 3. Review of Last Week Unix file system structure File types and access permissions Create and use directories and files

Filters: spell

For example, Mispeel was not flagged

Adds standard prefixes and suffixes to words in dictionary

Page 34: COMP 104: Intro to Unix Week 3. Review of Last Week Unix file system structure File types and access permissions Create and use directories and files

Filters: sort

The sort command sorts data (using ASCII format).

sort [-dfnru] [infile…] [-o outfile]>sort names -o sorted_namesor>sort names > sorted_names

Page 35: COMP 104: Intro to Unix Week 3. Review of Last Week Unix file system structure File types and access permissions Create and use directories and files

Filters: sort

Page 36: COMP 104: Intro to Unix Week 3. Review of Last Week Unix file system structure File types and access permissions Create and use directories and files

Filters: sort

Page 37: COMP 104: Intro to Unix Week 3. Review of Last Week Unix file system structure File types and access permissions Create and use directories and files

Filters: wc

The wc command counts lines, words, and characters.

wc [-lwc] [file…]

> wc -l document.txt

Page 38: COMP 104: Intro to Unix Week 3. Review of Last Week Unix file system structure File types and access permissions Create and use directories and files

wc options

-c Count bytes.-m Count characters.-C Same as -m.-l Count lines.-w Count words delimited by

white space characters or new line characters.

Page 39: COMP 104: Intro to Unix Week 3. Review of Last Week Unix file system structure File types and access permissions Create and use directories and files

In Class Assignment

Page 40: COMP 104: Intro to Unix Week 3. Review of Last Week Unix file system structure File types and access permissions Create and use directories and files

Question/Answer Session

Page 41: COMP 104: Intro to Unix Week 3. Review of Last Week Unix file system structure File types and access permissions Create and use directories and files

Activity 2

Page 42: COMP 104: Intro to Unix Week 3. Review of Last Week Unix file system structure File types and access permissions Create and use directories and files

Transferring files to einstein from your PC

WinSCP3 is software that provides secure FTP (File Transfer Protocol), which allows you to transfer files to and from a PC (freeware) Required for secure FTP to/from the class

Unix server einstein. Required for secure FTP from a remote

location, such as your home or your office Download WinSCP3and view directions at the

CLAS Lab Reference Manual web page: http://www.franklin.edu/programs/comp/resources/claslab/index_html/view

Page 43: COMP 104: Intro to Unix Week 3. Review of Last Week Unix file system structure File types and access permissions Create and use directories and files

Transferring files to einstein from your PC

Locate the WinSCP3 icon on your desktop and double click to open.

Page 44: COMP 104: Intro to Unix Week 3. Review of Last Week Unix file system structure File types and access permissions Create and use directories and files

Transferring files to einstein from your PC

Page 45: COMP 104: Intro to Unix Week 3. Review of Last Week Unix file system structure File types and access permissions Create and use directories and files

Transferring files to einstein from your PC

Page 46: COMP 104: Intro to Unix Week 3. Review of Last Week Unix file system structure File types and access permissions Create and use directories and files

Transferring files to einstein from your PC

Page 47: COMP 104: Intro to Unix Week 3. Review of Last Week Unix file system structure File types and access permissions Create and use directories and files

UNIX Utilities: ftp

FTP (File Transfer Protocol) allows you to transfer files to and from a remote network site (machine).

ftp [-dgintv] [hostname]

> ftp einstein.franklin.edu

Uses put and get commands to send and receive files.Type bin for setting binary transfer modeType prompt, to turn off promptingType ls, or dir for a directory listing

Page 48: COMP 104: Intro to Unix Week 3. Review of Last Week Unix file system structure File types and access permissions Create and use directories and files

UNIX Utilities: telnet

Telnet is a user interface to a remote system using the TELNET protocol.

telnet [-8ELcdr] [hostname]

> telnet einstein.franklin.edu

Page 49: COMP 104: Intro to Unix Week 3. Review of Last Week Unix file system structure File types and access permissions Create and use directories and files

UNIX Utilities: e-mail

Two most popular mail programs are elm and pine.

Note: Most Unix systems still have the “more basic” e-mail package called mail

Page 50: COMP 104: Intro to Unix Week 3. Review of Last Week Unix file system structure File types and access permissions Create and use directories and files

pine

The pine program has a menu-driven interface and is quite simple to use. One advantage of pine over elm is that it is very simple to include attachments.

> pine

- Follow the prompts in the menu

Page 51: COMP 104: Intro to Unix Week 3. Review of Last Week Unix file system structure File types and access permissions Create and use directories and files

elm

The elm program is the mail utility that is most often used. It is more difficult to use, but more powerful. It uses vi to compose messages.

> elm

Page 52: COMP 104: Intro to Unix Week 3. Review of Last Week Unix file system structure File types and access permissions Create and use directories and files

Question/Answer Session

Page 53: COMP 104: Intro to Unix Week 3. Review of Last Week Unix file system structure File types and access permissions Create and use directories and files

Break (10 Minutes)

Page 54: COMP 104: Intro to Unix Week 3. Review of Last Week Unix file system structure File types and access permissions Create and use directories and files

Activity 3

Page 55: COMP 104: Intro to Unix Week 3. Review of Last Week Unix file system structure File types and access permissions Create and use directories and files

Final Review: Week 1

History of Unix Unix design philosophy The Unix shell, variables and options Unix commands: alias, cat, date, echo, exit, finger,

hostname, login, lp, ls, man, more, passwd, set, setenv, uname, wc, whatis, whereis, who, whoami

Page 56: COMP 104: Intro to Unix Week 3. Review of Last Week Unix file system structure File types and access permissions Create and use directories and files

Final Review: Week 2

Unix file system structure File types and access permissions Create and use directories and files Edit files with vi (try on your

command line) Use the following Unix commands:

cd, chmod, cp, id, mkdir, mv, pwd, rm, rmdir, touch, umask, vi

Page 57: COMP 104: Intro to Unix Week 3. Review of Last Week Unix file system structure File types and access permissions Create and use directories and files

Final Review: Week 3

Unix processes Redirection, pipes, and filters Unix utilities (e-mail, ftp, telnet) Use the following Unix commands:

elm, ftp, grep, jobs, kill, look, pine, ps, sort, spell, telnet, uniq, wc

Page 58: COMP 104: Intro to Unix Week 3. Review of Last Week Unix file system structure File types and access permissions Create and use directories and files

Final Exam PoliciesExam Information

Prohibited Items: 

No Books No Notes No Dictionary No Calculator No Laptop No Access to any computers No Writing or scratch paper (extra paper will be supplied with the

exam)

Allowed Items:

Writing instrument.

 One hour in length allowed for taking the exam.

Page 59: COMP 104: Intro to Unix Week 3. Review of Last Week Unix file system structure File types and access permissions Create and use directories and files

Activity 4

Page 60: COMP 104: Intro to Unix Week 3. Review of Last Week Unix file system structure File types and access permissions Create and use directories and files

Please complete the course evaluation Need a student volunteer to collect and take

the evaluations to faculty services. 10 minute break after evaluation is complete.

Course Evaluation

Page 61: COMP 104: Intro to Unix Week 3. Review of Last Week Unix file system structure File types and access permissions Create and use directories and files

Break (10 Minutes)

Page 62: COMP 104: Intro to Unix Week 3. Review of Last Week Unix file system structure File types and access permissions Create and use directories and files

Activity 5

Page 63: COMP 104: Intro to Unix Week 3. Review of Last Week Unix file system structure File types and access permissions Create and use directories and files

Good Luck Everyone!!

Final Examination