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


{ 7 Comments }
  1. was helpful

  2. Thanks a lot!

  3. realy helpful, thanks!

  4. Thank you, it helped me a lot.

  5. how can add the data to the file without open the file in UNIX/Linux ?

  6. Great article!
    Thanks

  7. Thanks, ’twas helpful !!

Please post your comments/suggestions!