Introduction to UNIX - PowerPoint PPT Presentation

1 / 20
About This Presentation
Title:

Introduction to UNIX

Description:

2. Edit a command line using the replace function ... Ampersand & symbol to redirect STDERR. June 1, 1999. Using The C-Shell. 11 ... – PowerPoint PPT presentation

Number of Views:44
Avg rating:3.0/5.0
Slides: 21
Provided by: cic92
Category:

less

Transcript and Presenter's Notes

Title: Introduction to UNIX


1
Introduction to UNIX
  • F. Using C Shell Features

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 (gt, lt)
  • 6. Append results of a command to existing files
    (gtgt, gtgt)
  • 7. Use Pipes to link command data ()
  • 8. Construct simple aliases (alias)
  • 9. Recognize three basic error messages

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.

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

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 history15 (.cshrc)
  • To display the last n commands.
  • host history
  • 1 ls -l
  • 2 cd ths
  • 3 history

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 larlear
  • cd unix/class/handouts/learn

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

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

9
Command Line Editing
  • Substitution changes any previous command
  • host !7s/0/1
  • cat /home/ths/sunclass1/basics/history/cong
    rats
  • History list should be similar to the following
  • 7 cat /home/ths/sunclass0/basics/history/congrat
    s
  • 8 cat /home/ths/sunclass1/basics/history/congrat
    s
  • 9 history
  • 10 cat /home/ths/sunclass1/basics/history/congrats
  • 11 history

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 gt symbol to redirect STDOUT
  • Less-than lt symbol to redirect STDIN
  • Ampersand symbol to redirect STDERR

11
Redirecting Input/Output
  • Examples
  • host cat filea gt fileb (redirect
    creates fileb)
  • host cat filec gtgt fileb (appends to
    fileb)
  • host cat filed gt e.file (error msgs to
    e.file)
  • host cat filex gtgt e.file (append error to
    e.file)
  • host mail -s sub address lt file (get input
    from file)

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.

13
Using Pipes (Cont)
  • But you must count each line on the screen
  • ted ps -ax
  • PID TT STAT TIME COMMAND
  • 0 ? D 216 swapper
  • 1 ? IW 000 /sbin/init -
  • 2 ? D 012 pagedaemon
  • 55 ? IW 259 portmap
  • 60 ? IW 000 ypbind
  • 62 ? IW 000 keyserv
  • 73 ? S 157 (biod)
  • 74 ? S 157 (biod)
  • 75 ? S 157 (biod)
  • 76 ? S 156 (biod)
  • 87 ? IW 003 syslogd
  • 95 ? IW 000 rpc.statd
  • 97 ? IW 000 rpc.lockd
  • 101 ? IW 1101 automount
  • 104 ? S 041 screenblank
  • 109 ? S 2021 update

14
Use of Pipes - (Cont)
  • There are several solutions to this problem
  • Solution 1
  • host ps -ax gt 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?

15
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 1418 outdis
  • drwxr-xr-x 2 pam 512 Jan 22 1107 remodel
  • -rwxr-xr-x 1 pam 102 Jun 19 1255 test.out

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 1418 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 1107 remodel
  • -rwxr-xr-x 1 pam 102 Jun 19 255 test.out

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 1418 outdis
  • -rwxr-xr-x 1 pam 972 Aug 19 1255 test.out

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
19
More Complex Aliases
  • Importing an argument
  • alias chklog 'grep \! log. more'
  • host chklog reg1
  • alias cnt 'grep -c \! log.'
  • alias f 'finger \!_at_lanl.gov'

Argument
List of files
Alias name
20
End of Module
Complete Using C Shell Function Exercises
Write a Comment
User Comments (0)
About PowerShow.com