Append vs Truncate

Download bash eBook

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

Stats

Contributors: 3
2016-09-09
Licensed under: CC-BY-SA

Not affiliated with Stack Overflow
Rip Tutorial: info@zzzprojects.com

Download eBook