/* Code-Comments */

December 20, 2019

Redirection In Unix - AKA Angled Brackets

Today I wanted to learn how to programmatically update a file with shell scripting.

Turns out that there are multiple approaches and it depends on whether or not you’re okay with a destructive action or not.

The short answer: > will push data from what’s to the left of the bracket to the right. This is potentially destructive. >> will push data in a non-destructive way by appending the data only.

I found Paul Brown’s tutorial on the differences between the angle brackets over at Linux.com really accessible and informative.

For an even more in-depth look, the Advanced Bash-Scripting Guide has a great chapter on Redirection is fantastic and contains lots of relevant examples.

Update: A few more examples on ways to use standard redirects (>) courtesy of Warren Hill’s answer on StackExchange:

  • > file redirects stdout to file
  • 1> file redirects stdout to file
  • 2> file redirects stderr to file
  • &> file redirects stdout and stderr to file

Stephen Weiss

Thanks for reading! My name's Stephen Weiss. I live in Chicago with my wife, Kate, and dog, Finn.
Click here to see the archives of my weeks in review and sign up yourself!