Week3

advertisement
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
Edit files with vi
Use the following Unix commands:
cd, chmod, cp, id, mkdir, mv, pwd, rm, rmdir,
touch, umask, vi
Agenda – Activity 1

Introduction to Unix Processes



Foreground Process
Background Process
Running Processes in the background


Suspending Processes


& character
^Z special key
Displaying suspended jobs

jobs command
Agenda – Activity 1 Continued

Displaying status of processes


Killing Processes


ps command
kill, and kill –9 command
In Class Exercise
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
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)
Agenda – Activity 3

Review for Today’s Final Exam
Agenda – Activity 4


Course Evaluation
Break (10 minutes)
Agenda – Activity 5

Take the Final Exam!
Activity 1
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
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>
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.
Running Processes in Background
Type an ampersand (&) after the command
to run it in the background
>find . –name java > javaLocations.txt &
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]
Displaying List of Suspended Jobs
/export/home/morris07> jobs
…
[1]
Stopped
vi document
[2]
Stopped
elm
-l option gives more information
Displaying Status of Processes
Use ps to report the status of a process
/export/home/morris07>ps
…
PID TTY TIME
CMD
19834 pts/7 0:05
ksh
19954 pts/7 0:04
ps
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.
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
In Class Exercise
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
Start vi /etc/motd
In Command Mode type ^Z
Type jobs -l to see any suspended jobs
Type fg to bring last suspended job to foreground.
In Command Mode type ^Z
Type jobs -l to see any suspended jobs
Type kill {Process ID} to kill the process
Type ps to get current list of processes
If the process is still running, type ‘kill –9 {Process
ID}
Type ps to get current list of processes
Question/Answer Session
Standard Input and Output
keyboard
command
command
standard input
terminal
standard output
Redirection and Pipes
Redirecting Standard Output to a File
with: ‘>’, ‘>>’
command
command
ls –al > mylist
ls –al >> mylist
terminal
file
standard output
redirected output
(creates or overwrites file)
(appends or creates file)
Redirection and Pipes
Redirecting Standard Output to a Command
with: ‘|’
command
terminal
standard output
command
command
redirected output
ls –al | more
(passes output to command)
Redirection and Pipes
Redirecting Standard Input from a File with: ‘<’
keyboard
file
cat < file
command
standard input
command
redirected input
(passes file to command)
Filters
A FILTER is any program that reads from
Standard Input and writes to Standard
Output.
grep
uniq
look
spell
sort
wc
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
Demonstration - grep
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
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.
Filters: look
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
Filters: spell

For example,


Mispeel was not flagged
Adds standard prefixes and suffixes to
words in dictionary
Filters: sort
The sort command sorts data (using ASCII
format).
sort [-dfnru] [infile…] [-o outfile]
>sort names -o sorted_names
or
>sort names > sorted_names
Filters: sort
Filters: sort
Filters: wc
The wc command counts lines, words, and
characters.
wc [-lwc] [file…]
> wc -l document.txt
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.
In Class Assignment
Question/Answer Session
Activity 2
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
Transferring files to einstein from your PC
Locate the WinSCP3
icon on your
desktop and
double click to
open.
Transferring files to einstein from your PC
Transferring files to einstein from your PC
Transferring files to einstein from your PC
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 mode
Type prompt, to turn off prompting
Type ls, or dir for a directory listing
UNIX Utilities: telnet
Telnet is a user interface to a remote system
using the TELNET protocol.
telnet [-8ELcdr] [hostname]
> telnet einstein.franklin.edu
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
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
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
Question/Answer Session
Break (10 Minutes)
Activity 3
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
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
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
Final Exam Policies
Exam Information
Prohibited Items:







No
No
No
No
No
No
No
Books
Notes
Dictionary
Calculator
Laptop
Access to any computers
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.
Activity 4
Course Evaluation

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.
Break (10 Minutes)
Activity 5
Final Examination

Good Luck Everyone!!
Download