How to append string/data to a file in Linux

This article will show you how to append a string (or any data) to the end of a file under Linux/Unix. Appending is done very simply by using the append redirect operator >>. Simply use the operator in the format data_to_append >> filename and you’re done. Below are several examples:

Examples to Append Data to a File

  1. To append the string “hello” to file greetings.txt
  2. echo "hello" >> greetings.txt

  3. To append the contents of the file temp.txt to file data.txt
  4. cat temp.txt >> data.txt

  5. To append the current date/time timestamp to the file dates.txt
  6. date >> dates.txt


Tell us what you think about this article!