1 / 20

Introduction to UNIX

Introduction to UNIX. F. Using C Shell Features. Using C Shell Features. Performance Objectives 1. Use History to recall/repeat commands ( history, !, !! ) 2. Edit a command line using the replace function( ^ ) 3. Edit a command line using the substitution method ( :s )

Download Presentation

Introduction 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. Introduction to UNIX F. Using C Shell Features Using The C-Shell

  2. Using C Shell Features Performance Objectives 1. Use History to recall/repeat commands (history, !, !!) 2. Edit a command line using the replace function(^) 3. Edit a command line using the substitution method (:s) 4. Identify the concept of STDIN/STDOUT/STDERR 5. Redirect data Input and Output (>, <) 6. Append results of a command to existing files (>>, >>&) 7. Use Pipes to link command data (|) 8. Construct simple aliases (alias) 9. Recognize three basic error messages Using The C-Shell

  3. Shell Initialization and Termination • Activities: • Reads .cshrc from home directory when new C shell started. • Reads .login when initiated as a login shell. • Reads .logout when shell terminated (if the login shell) • Operates in either interactive or non-interactive (batch) mode. Using The C-Shell

  4. Built-in Commands • C Shell contains built-in commands: alias fg/bg echo history ignoreeof jobs kill noclobber noglob set setenv source stop suspend umask unalias • The man page for csh is very long (about 100 screens). • Use the man search feature (/keyword). Using The C-Shell

  5. The History Mechanism • Command Line Editing Allows you to: • rerun any command in the history buffer, and • change/correct commands in the history buffer. • To set up a history list: set history=15 (.cshrc) • To display the last n commands. host% history 1 ls -l 2 cd ~ths 3 history Using The C-Shell

  6. Command Line Editing • To make a new simpler command: host% alias hb history • Note the following: host% cd unix/class/handouts/larn unix/class/handouts/larn: No such file or directory host% ^lar^lear^ cd unix/class/handouts/learn Using The C-Shell

  7. Command Line Editing • A display of the history buffer reveals: host% history 2 cd ~ths 3 history 4 cd unix/class/handouts/larn 5 cd unix/class/handouts/learn 6 history • To recall a previous command: host% !cd host% !5 Using The C-Shell

  8. Command Line Editing • You can list the last n commands from the history buffer: host% history 6 4 cd unix/class/handouts/larn 5 cd unix/class/handouts/learn 6 history 7 cat /home/ths/class0/basics/history/congrats 8 cat /etc/motd 9 history • To rerun the correct cd command - !5 or !cd Using The C-Shell

  9. Command Line Editing • Substitution changes any previous command: host% !7:s/0/1 cat /home/ths/sunclass1/basics/history/congrats • History list should be similar to the following: 7 cat /home/ths/sunclass0/basics/history/congrats 8 cat /home/ths/sunclass1/basics/history/congrats 9 history 10 cat /home/ths/sunclass1/basics/history/congrats 11 history Using The C-Shell

  10. Redirecting Input/Output • The 3 UNIX standard files are, the terminal. • STDIN (keyboard) • STDOUT (display) • STDERR (display) • To redirect output to another file, use: • Greater-than > symbol to redirect STDOUT • Less-than < symbol to redirect STDIN • Ampersand & symbol to redirect STDERR Using The C-Shell

  11. Redirecting Input/Output • Examples: • host% cat filea > fileb (redirect creates fileb) • host% cat filec >> fileb (appends to fileb) • host% cat filed >& e.file (error msgs to e.file) • host% cat filex >>& e.file (append error to e.file) • host% mail -s “sub” address < file (get input from file) Using The C-Shell

  12. Use of Pipes - | • Special symbol “|” command [options] | command [options] | ... • Problem: • How many processes are running on your machine? • The command ps -ax will show all processes on a machine. Using The C-Shell

  13. Using Pipes (Con’t) • But you must count each line on the screen: ted% ps -ax PID TT STAT TIME COMMAND 0 ? D 2:16 swapper 1 ? IW 0:00 /sbin/init - 2 ? D 0:12 pagedaemon 55 ? IW 2:59 portmap 60 ? IW 0:00 ypbind 62 ? IW 0:00 keyserv 73 ? S 1:57 (biod) 74 ? S 1:57 (biod) 75 ? S 1:57 (biod) 76 ? S 1:56 (biod) 87 ? IW 0:03 syslogd 95 ? IW 0:00 rpc.statd 97 ? IW 0:00 rpc.lockd 101 ? IW 11:01 automount 104 ? S 0:41 screenblank 109 ? S 20:21 update 112 ? IW 0:03 cron Using The C-Shell

  14. Use of Pipes - | (Con’t) • There are several solutions to this problem: • Solution 1 host% ps -ax > psfile host% wc -l psfile • Note the number of processes • Solution 2 host% ps -ax | wc -l • Note the number of processes • Why is there a difference of one process? Using The C-Shell

  15. Using Filters with Pipes • Lists are often difficult to preview visually: host% ls -lproduces a long list of all files. -rw-r--r-- 1 pam 880 Sep 28 1988 Aug.notes drwxr-xr-x 2 pam 512 Oct 23 1985 bin -rw-r--r-- 1 pam 129 Aug 20 1986 complex.f -rw------- 1 pam 129 Jul 2 1987 mbox -rw-r--r-- 1 pam 429 Aug 16 14:18 outdis drwxr-xr-x 2 pam 512 Jan 22 11:07 remodel -rwxr-xr-x 1 pam 102 Jun 19 12:55 test.out Using The C-Shell

  16. Using Filters with Pipes - grep • To search a file for a specified string: host% ls -l | grep Aug -rw-r--r-- 1 pam 129 Aug 20 1986 complex.f -rw-r--r-- 1 pam 4291 Aug 16 14:18 outdis -rw-r--r-- 1 pam 880 Sep 28 1988 Aug.notes • To search a file for all but specified string: host% ls -l | grep -v Aug drwxr-xr-x 2 pam 512 Oct 23 1985 bin -rw------- 1 pam 129 Jul 21 1987 mbox drwxr-xr-x 2 pam 512 Jan 22 11:07 remodel -rwxr-xr-x 1 pam 102 Jun 19 2:55 test.out Using The C-Shell

  17. Using Filters - pipes, grep & sort • Consider the next example: host% ls -l | grep Aug | sort +4 -rw-r--r-- 1 pam 129 Aug 20 1986 complex.f drwxr-xr-x 2 pam 512 Aug 23 1985 bin -rw-r--r-- 1 pam 880 Sep 28 1988 Aug.notes -rw-r--r-- 1 pam 929 Aug 16 14:18 outdis -rwxr-xr-x 1 pam 972 Aug 19 12:55 test.out Using The C-Shell

  18. Constructing Simple Aliases • Examine the following aliases: alias rm rm -i • Full pathnames are preferred: • alias cp /bin/cp -I • Enclose complex commands in “quotes” • alias ls "pwd; /bin/ls -sFC" Command Alias name Command line Using The C-Shell

  19. More Complex Aliases • Importing an argument: alias chklog 'grep \!*log.* | more' • host% chklog reg1 • alias cnt 'grep -c \!* log.*' • alias f 'finger “\!*”@lanl.gov' Argument List of files Alias name Using The C-Shell

  20. End of Module Complete Using C Shell Function Exercises Using The C-Shell

More Related