27

When using echo "foo">> bar.txt more than once it appends to the end of a file. How to overwrite bar.txt each time?

J.Olufsen
  • 3,682
  • 2
    Dennis' answer is correct. See man bash and search (using /) for the section on "REDIRECTION". Specifically subsections "Redirecting Output" and "Appending Redirected Output". – RedGrittyBrick Apr 19 '12 at 18:57

1 Answers1

49

> is for redirecting to a file (overwriting it), while >> is for appending.

To overwrite bar.txt, use this:

echo "foo" > bar.txt
Dennis
  • 49,727