Felitaur Site 
  Offerings
  
 | 
   
 | 
  
   
   
 
 Piping and Redirection 
 
Lecture Overview Index | Linux SysAdmin Homepage
| Overview | 
 
Goals: 
- 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
  
 | 
 
| Questions | 
 
| 
 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 | 
 
 
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
  
 | 
 
| Resources | 
 
| 
  | 
 
 
 
   |    
   
    
 |