What's the difference between using > and >>?

How can I use both < and > (redirection operators) in a single command?

link|improve this question
3  
Please can you break this into separate questions. – Diago Sep 3 '10 at 14:51
Smells like homework.... – Nifle Sep 3 '10 at 14:55
Nah, I was just reading 'Learning the shell' and I was just wondering about a few things. I'm assuming `` is command redirection, {} is for lists, and "" is to help bash understand the command. I'm a little confused on the whole echo thing though. I'm assuming I'd just say FIRST=name etc and then just echo Last, middle, ssn etc I just want a better understanding. – Tallow Sep 3 '10 at 15:06
I suggest you follow Diago's advice. This site works best when there is a single question that can be answered. So go ahead and ask four different questions, it's not like we charge extra... – Nifle Sep 3 '10 at 15:15
Thanks for doing as we asked. – Nifle Sep 3 '10 at 15:38
feedback

2 Answers

> redirects data from stdout (read standard out) to a file.

ls -a > my-files.txt

will take the output of ls -a and put it into a file named my-files.txt deleting/overwriting the file if it exists. Using >> instead of > in the example above will not overwrite the file if it exists but add the output of ls -a to the end of my-files.txt

< on the other hand sends data to a programs stdin (read standard in). If I have a file called my-files.txtand I want to know how many words it contains I can send it to a program called wc. This program accepts data on it's stdin so to the data to it I do

wc -w < my-files.txt

And lastly If I want to save the output of that command to a new file I can use both like so

wc -w < my-files.txt > wordcount.txt

link|improve this answer
feedback

Try,
Advanced Bash-Scripting Guide
An in-depth exploration of the art of shell scripting

  1. Special Characters, Quoting
  2. IO Redirection
  3. Introduction to Variables and Parameters
link|improve this answer
feedback

Your Answer

 
or
required, but never shown

Not the answer you're looking for? Browse other questions tagged or ask your own question.