Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

i am newbie and don't know much about bash.my instructor asked me to do cat script and observer the output and then tell What is > operator and what is the difference between > & >> operator? and i am unable to find any justifications.so,any help please :)

share|improve this question

closed as off topic by John Gardeniers, Sirex, MadHatter, Tom O'Connor, Ward Oct 17 '12 at 7:31

Questions on Server Fault are expected to relate to professional server, networking, or related infrastructure administration within the scope defined by the community. Consider editing the question or leaving comments for improvement if you believe the question can be reworded to fit within the scope. Read more about reopening questions here.If this question can be reworded to fit the rules in the help center, please edit the question.

    
You could fiddle with temporary files to get the difference between >> and >. –  halp Nov 1 '10 at 2:18

3 Answers 3

The ">" sign is used for redirecting the output of a program to something other than stdout (standard output, which is the terminal by default).

The >> appends to a file or creates the file if it doesn't exist.
The > overwrites the file if it exists or creates it if it doesn't exist.

In either case, the output of the program is stored in the file whose name is provided after the redirection operator.

Examples:
$ ls > allmyfiles.txt creates the file "allmyfiles.txt" and fills it with the directory listing from the ls command

$ echo "End of directory listing" >> allmyfiles.txt adds "End of directory listing" to the end of the file "allmyfiles.txt"

$ > newzerobytefile creates a new zero byte file with the name "newzerobytefile" or overwrites an existing file of the same name (making it zero bytes in size)

share|improve this answer
3  
More IO redirection awesomeness: tldp.org/LDP/abs/html/io-redirection.html –  Tim Bielawa Oct 31 '10 at 23:59

Unable to locate the manual page of bash? Just type man bash at the command prompt.

share|improve this answer
    
You could try and add come useful content to your comment. They did just have a blog post talking about RTFM style answers blog.serverfault.com/post/1306724710/rtfm Maybe you could mention that the > and >> operators are used for IO redirection tldp.org/LDP/abs/html/io-redirection.html Likewise < is used to read a file into stdin. –  Tim Bielawa Oct 31 '10 at 23:59
    
I agree with @Tim. I'm all in favor of the "teach a man to fish" method of learning. In this case, though, and especially for a beginner, there's zero indication that output redirectors are handled by the user's shell. –  EEAA Nov 1 '10 at 0:06
    
-1 because the bash manpage is one of the hardest to follow that I have to deal with on a regular basis. –  Sparr Nov 1 '10 at 2:35
    
Oh come on! This is not RTFM! You can go to the manpage of bash (and I provided a link to it) press ctrl-F and type >> The first thing it shows is the usage of >> Plus, this question is homework: Do we answer homework (it was answered by andyh_ky) or do we show where the answer is? –  adamo Nov 1 '10 at 6:24
    
How is telling him to look for "the manual page of bash" not a case of Read The F****** Manual? It's even got the word manual in it! –  Sam Nov 1 '10 at 17:24

=> th > operator use to overwrite the file if exist other wise it will create new file E.X. cat >example1 => If file 'example1' is exist than it will over write else create new file => the >> operator use to append the end of the file E.X. cat >>example1

share|improve this answer
    
thanks for use it.....! –  Godani Bhavesh Oct 16 '12 at 6:22
2  
That is exactly the same information as andyh_ky posted previously. There is no point in repeating a previous answer. There is also no point in adding a meaningless comment. –  John Gardeniers Oct 16 '12 at 6:32

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