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
- To append the string “hello” to file greetings.txt
- To append the contents of the file temp.txt to file data.txt
- To append the current date/time timestamp to the file dates.txt
echo "hello" >> greetings.txt
cat temp.txt >> data.txt
date >> dates.txt