Tools and Concepts - PowerPoint PPT Presentation

1 / 34
About This Presentation
Title:

Tools and Concepts

Description:

if the attribute is numeric, it follows these rules: ... files, the second file will be overwritten with the uniq output from the first file ... – PowerPoint PPT presentation

Number of Views:44
Avg rating:3.0/5.0
Slides: 35
Provided by: richardg66
Category:

less

Transcript and Presenter's Notes

Title: Tools and Concepts


1
Chapter 9
  • Tools and Concepts

2
find
  • Very powerful command used to locate files
  • conditions are things like name, or attributes
  • if the attribute is numeric, it follows these
    rules
  • unsigned attribute matches exactly that number
  • attribute matches greater than that number
  • -attribute matches less than that number
  • can code -exec command \ to execute the
    command on any file that matches the condition
  • careful construction allows great efficiency

3
pipe
  • First implemented in 1972
  • Allows user to construct powerful command sets
  • Commands in a pipe are in pseudo-simultaneous
    execution
  • To be used in a pipe, each process except the
    endmost two must be filters

4
The Filter Program Concept
  • A filter is a process with the following
    characteristics
  • it reads from standard input
  • it writes good data to standard output
  • while not required, it should send errors to
    standard error
  • Most Unix programs are filters, that allows them
    to be used in pipes.

5
tee
  • You can insert a tee into a pipe to capture
    intermediate results
  • the data can only be redirected into a file
  • the tee does not affect the flow of data
  • you CANNOT create parallel pipes with a tee
  • they are very useful for debugging pipes

6
redirection (lt, gt, gtgt)
  • Besides piping the data, it is possible to send
    the output of a process or pipe to a file, or to
    take input from a file.
  • This is possible because a file is a stream of
    bytes.
  • The keyboard creates a stream of bytes
  • The screen sees a stream of bytes

7
redirecting standard output (gt)
  • Used to store the output of a command or pipe in
    a file.
  • Remember the rule
  • When a file is the target of a redirection, the
    first thing that happens is the next byte pointer
    is set to byte zero
  • You can redirect any filter and any command that
    sends output to standard out

8
Appending gtgt
  • If you choose the append operator gtgt you will add
    the current output to the end of the existing
    file.
  • Some flavors require that the file you are
    appending to exist, others will create the file
    if it doesnt exist.

9
redirecting standard error
  • Error messages are important clues to problems.
  • You should always evaluate any error messages you
    are sent.
  • You should never allow users to see error
    messages!
  • The two shells handle this situation differently

10
redirecting standard errorC shell version
  • Sending both error and out to the same file is
    straight forward

11
redirecting standard errorC shell (cont.)
  • First redirect just output
  • Then using gt redirect both output and error to
    the same file.

12
redirecting standard error C shell (cont.)
  • Sending standard out to one file and error to
    another is a little tricky in csh.

13
redirecting standard error C shell (cont.)
  • Create a sub-shell to run the command.
  • Redirect standard out to one file in the
    sub-shell.
  • Redirect standard error to another file outside
    the sub-shell.

Pay close attention to the difference in the
figure between parentheses and redirection.
14
Redirecting standard output Bourne Shell
  • The Bourne shell references the three standard
    files by number
  • File 0 - standard input
  • File 1 - standard output
  • File 2 - standard error
  • Just redirecting standard out is the same as in
    the C shell

15
Redirecting standard error Bourne Shell
  • Sending output to one file and error to another
    is simple in the Bourne shell

16
Redirecting standard error Bourne Shell (cont.)
  • Sending output and error to the same file is al
    little more intricate
  • Send file1 to filename, and send file 2 to the
    same place.

17
Redirecting standard input (lt)
  • Most commands have evolved to take files on the
    command line and do their own input redirection.
  • The only command that requires redirection of
    standard input is translate (tr).
  • You can redirect standard input into most
    commands but it is a waste of a character.

18
Here document ltlt
  • You can create an input stream within a script by
    using a here document.
  • Bourne added this feature in response to faster
    computers that read ahead.
  • Useful way to produce preformatted output in
    scripts.

19
alias
  • Used to create new commands
  • Some aliases protect the users, like alias cp
    cp -i
  • It is dangerous to depend on aliases because
  • they arent always there
  • they arent always the same
  • you can forget how the real command works

20
alias (cont.)
  • Some rules for building aliases
  • be sure you know what you are creating
  • dont use one character aliases
  • dont create aliases using other OS commands
  • dont use questionable language
  • wait until you understand a command before you
    alias it

21
unalias
  • Used to remove an alias from the alias table
  • Be careful about the aliases you unalias, you may
    want them later!

22
diff
  • Used to find differences between two files
  • Useful to track changes in a file
  • can create output in ed format so you can make
    the two files look the same
  • neither file is changed by diff

23
uniq
  • Used to remove duplicate, concurrent lines in a
    file.
  • The -c (count) option tells you how many
    duplicate lines there were
  • if used with two files, the second file will be
    overwritten with the uniq output from the first
    file

24
File Name Completion
  • Really nice feature of many shells
  • usually invoked by ltESCgt or ltTABgt depending upon
    the shell
  • making file names unique near the beginning
    facilitates file name completion
  • in some shells D shows you a partial file list
    that matches your pattern
  • yet another way to be more efficient in Unix

25
Shell Variables
  • A variable is a mnemonic for a place.
  • A variable name is the identifier for a location
    in memory.
  • A variable value is the datum stored at the
    location specified by the variable name.
  • Initializing variables varies between shells
  • C shell use set variable value
  • Bourne shells use variablevalue

26
set
  • To create variables in the C shell use the set
    command
  • you can assign values to variables
  • you can set particular variables like filec as
    switches
  • shell variables exist only in the instance of the
    shell that created them unless you make them
    available to subsequent shells

27
setenv
  • Used to make a variable available to subsequent
    shells.
  • The variable becomes part of the environment
    passed to the child process
  • Normally environmental variables are coded in
    upper case
  • In most systems environmental variables are
    available to all descendent instances of the shell

28
unsetenv
  • Used to remove a variable from the environment of
    newly created child processes
  • dont try to unsetenv any variable you dont
    create
  • once a variable is unsetenv it will no longer be
    available to subsequent shells

29
export
  • In the Bourne shell you export variables to make
    them available to child processes
  • the child process receives the variable and value
    as part of its environment
  • any change to the variable will NOT be reflected
    in the parent process

30
Startup files .login
  • Run once when you log into the system
  • Use this file to set up the environment that is
    common to all shells
  • This is a good place to set your backspace
    key stty erase H
  • Also a good place to set up an X-windows
    environment

31
Startup files .cshrc
  • Run each time a new instance of the C shell is
    forked
  • Use this file to set up your C shell variables
    and C shell dependent elements
  • A good place to set aliases
  • I always set filec here
  • The rc in the file name stands for runnable
    commands

32
Startup files .bashrc
  • Used to initialize the environment for the bash
    shell.
  • This is the place to setup your bash aliases and
    the like

33
Setup files .profile
  • This setup file is for the Bourne shell.
  • It predates the idea of runnable commands so
    doesnt end with rc.
  • Usually this is a small files as the Bourne shell
    doesnt have all that stuff to set up like
    aliases.

34
Other Setup files
  • Most shells have a setup file you can use
  • T shell - .tcshrc
  • Z shell - .zcshrc
  • The use of theses files is optional, but a wise
    user will utilize the efficiency available.
Write a Comment
User Comments (0)
About PowerShow.com