Presentation is loading. Please wait.

Presentation is loading. Please wait.

June 1, 1999Using The C-Shell1 Introduction to UNIX F. Using C Shell Features.

Similar presentations


Presentation on theme: "June 1, 1999Using The C-Shell1 Introduction to UNIX F. Using C Shell Features."— Presentation transcript:

1 June 1, 1999Using The C-Shell1 Introduction to UNIX F. Using C Shell Features

2 June 1, 1999Using The C-Shell2 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

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

4 June 1, 1999Using The C-Shell4 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).

5 June 1, 1999Using The C-Shell5 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

6 June 1, 1999Using The C-Shell6 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

7 June 1, 1999Using The C-Shell7 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

8 June 1, 1999Using The C-Shell8 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

9 June 1, 1999Using The C-Shell9 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

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

11 June 1, 1999Using The C-Shell11 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)

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

13 June 1, 1999Using The C-Shell13 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

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

15 June 1, 1999Using The C-Shell15 Using Filters with Pipes Lists are often difficult to preview visually: host% ls -l produces 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

16 June 1, 1999Using The C-Shell16 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

17 June 1, 1999Using The C-Shell17 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

18 June 1, 1999Using The C-Shell18 Constructing Simple Aliases Examine the following aliases: alias rm rm -i Full pathnames are preferred: n alias cp /bin/cp -I Enclose complex commands in “quotes” n alias ls "pwd; /bin/ls -sFC" CommandAlias nameCommand line

19 June 1, 1999Using The C-Shell19 More Complex Aliases Importing an argument: alias chklog 'grep \!* log.* | more' è host% chklog reg1 alias cnt 'grep -c \!* log.*' alias f 'finger “\!*”@lanl.gov' Alias name ArgumentList of files

20 June 1, 1999Using The C-Shell20 End of Module Complete Using C Shell Function Exercises


Download ppt "June 1, 1999Using The C-Shell1 Introduction to UNIX F. Using C Shell Features."

Similar presentations


Ads by Google