Bash Append vs Truncate

Download Bash for free

Example

Truncate >

  1. Create specified file if it does not exist.
  2. Truncate (remove file's content)
  3. Write to file
$ echo "first line" > /tmp/lines
$ echo "second line" > /tmp/lines

$ cat /tmp/lines
second line

Append >>

  1. Create specified file if it does not exist.
  2. Append file (writing at end of file).
# Overwrite existing file
$ echo "first line" > /tmp/lines

# Append a second line
$ echo "second line" >> /tmp/lines

$ cat /tmp/lines
first line
second line
Print error messages to stderr