630 likes | 784 Views
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.
E N D
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 • & character • Suspending Processes • ^Z special key • Displaying suspended jobs • jobs command
Agenda – Activity 1 Continued • Displaying status of processes • ps command • Killing Processes • 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!
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 • 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
terminal command standard output Standard Input and Output keyboard command standard input
terminal command standard output redirected output file command Redirection and Pipes Redirecting Standard Output to a File with: ‘>’, ‘>>’ ls –al > mylist(creates or overwrites file) ls –al >> mylist(appends or creates file)
terminal command standard output command command redirected output Redirection and Pipes Redirecting Standard Output to a Command with: ‘|’ ls –al | more(passes output to command)
redirected input Redirection and Pipes Redirecting Standard Input from a File with: ‘<’ cat < file(passes file to command) keyboard command standard input file 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
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: 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: 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.
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.
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