1 / 63

COMP 104: Intro to Unix

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.

radley
Download Presentation

COMP 104: Intro to Unix

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. COMP 104: Intro to Unix Week 3

  2. 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

  3. 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

  4. Agenda – Activity 1 Continued • Displaying status of processes • ps command • Killing Processes • kill, and kill–9 command • In Class Exercise

  5. 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

  6. 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)

  7. Agenda – Activity 3 • Review for Today’s Final Exam

  8. Agenda – Activity 4 • Course Evaluation • Break (10 minutes)

  9. Agenda – Activity 5 • Take the Final Exam!

  10. Activity 1

  11. 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

  12. 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>

  13. 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.

  14. Running Processes in Background Type an ampersand (&) after the command to run it in the background > find . –name java > javaLocations.txt &

  15. 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]

  16. Displaying List of Suspended Jobs /export/home/morris07> jobs … [1] Stopped vi document [2] Stopped elm -l option gives more information

  17. 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

  18. 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.

  19. 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

  20. 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

  21. Question/Answer Session

  22. terminal command standard output Standard Input and Output keyboard command standard input

  23. 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)

  24. 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)

  25. redirected input Redirection and Pipes Redirecting Standard Input from a File with: ‘<’ cat < file(passes file to command) keyboard command standard input file command

  26. Filters A FILTER is any program that reads from Standard Input and writes to Standard Output. grep uniq look spell sort wc

  27. 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

  28. Demonstration - grep

  29. 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

  30. 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.

  31. Filters: look

  32. 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

  33. Filters: spell • For example, • Mispeel was not flagged • Adds standard prefixes and suffixes to words in dictionary

  34. 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

  35. Filters: sort

  36. Filters: sort

  37. Filters: wc The wc command counts lines, words, and characters. wc [-lwc][file…] >wc -l document.txt

  38. 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.

  39. In Class Assignment

  40. Question/Answer Session

  41. Activity 2

  42. 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

  43. Transferring files to einstein from your PC Locate the WinSCP3 icon on your desktop and double click to open.

  44. Transferring files to einstein from your PC

  45. Transferring files to einstein from your PC

  46. Transferring files to einstein from your PC

  47. 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

  48. UNIX Utilities: telnet Telnet is a user interface to a remote system using the TELNET protocol. telnet [-8ELcdr][hostname] >telnet einstein.franklin.edu

  49. 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

  50. 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

More Related