logo © 1996 Phil Waclawski
Felitaur Site
About Me
ftp files
Help Files
What's New?
Home Page
Other Links
Anatomy &
Fun Links
Win 95/NT
Comments or
webmaster@ felitaur.com
Piping and Redirection
Lecture Overview Index | Linux SysAdmin Homepage
  • Learn the power involved in using piping to connect small programs together.
  • Understand the different forms of redirection, and why to be careful which you use.
  • How to use grep, a powerful tool for searching text for patterns.
  • How to use the sort command.
The following programs/files/directories will be discussed for this topic
  • | (the pipe, for programs)
  • > (redirect output, but wipes out file if it exists)
  • >> (redirect output, but appends)
  • < (redirect input, often from a file)
    mail -s "subject line" user@domain.com < fileforbodyofemail
  • >& (send output to yet another output)
    ls /etc ABC > lsoutput 2>&1
  • | tee filename
  • grep and grep -v
  • sort
  • ls | less vs. ls > less, Why is one good, the other not a good idea?
  • What command(s) would you use to sort the password file by login name, then view it screen by screen?
  • What is stdin stdout and stderr? Why should we care? ;)
  • Using ls -l, piping and the sort command, how could you get a list of all the files in a directory sorted from smallest to largest file?
  • ps -ef lists all processes, so how would you only find processes that you own?
  • For regular expressions, what meaning does ^ and $ have?
  • What does grep -v do? How can you use grep to filter a file?
  • Activities & Assignments
    • Using a text editor, create the following file (call it havingfun)

      Life can be fun or not
      fun is as fun does
      Boy, isn't this funny
      I don't think this is fun
      funny how strange life can be

    • Now, try the following commands:
      • grep fun havingfun
      • grep fun$ havingfun
      • grep ^fun havingfun
      • grep fun *
    • What lines show up? Why?
    • Try banner "some message here" | write username
      (where username is a friends, or your own username)
    • banner "Sock it to me?" | mail username
      (Told you there was a reason to have mail around ;)

    Note: There are MANY commands that use stdin and stdout, and you'll soon develop a group of your favorites, such as the following:
    • awk '{print $1}' (with -F and a filename, for grabbing columns out of a file)
    • diff (comparing differences between files, makes a "patch" file as well)
    • echo and echo -e
    • head (show top 10 lines of file, modified by options)
    • tail and esp. tail -f (shows bottom 10 lines of file, modified by options, -f lets you KEEP seeing the last 10 lines of a logfile)
    • tail -f /home/web/logs/error_log | grep username
    • uniq (remove duplicate lines)
    • wc (display line, word and character counts)
    • who (as in who is online)
    • date (display date and time in many formats)
    • ps
    • less/more