I don't know much about bash.

My instructor asked me to make a cat script and to observe the output and then tell what is the operator > and what is the difference between the operators > & >>.

I am unable to find any justifications. Could you help?

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

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.

$ 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)


=> 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

  • 4
    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

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

  • 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 Cogan Nov 1 '10 at 17:24

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