This address http://comexchan.cnblogs.com/, author Comex Chan, respecting intellectual property rights, reproduced please specify the source, thank you!
=======================================================
Overwrite a file content directly or create a new file
=======================================================
First of all, we're looking at a test file that doesn't exist at first.
ll/tmp/
Then perform the test
cat << EOF >/tmp/test_cat_and_eof_by_comexchan-cnblogs-com_1 test cat with EOF for file overwrite or new EOF
We are looking at the contents of the file:
Cat /tmp/test_cat_and_eof_by_comexchan-cnblogs-com_1
Execute again to see if it will overwrite
cat << EOF >/tmp/test_cat_and_eof_by_comexchan-cnblogs-com_1 test cat with EOF implementation file overwrite or new [this is the second Test] EOF
Then look at the contents of the file:
Overwrite success!
=================================================
Cat combines EOF for file append
=================================================
First add some content to test
cat << EOF >/tmp/test_cat_and_eof_by_comexchan-cnblogs-com_2 test cat with EOF implementation file append [ First add some content to test]http://comexchan.cnblogs.com/EOF
And then perform the Append
cat << EOF >>/tmp/test_cat_and_eof_by_comexchan-cnblogs-com_2 test cat with EOF implementation file append [ This is the 2nd time. Append partial text]http://comexchan.cnblogs.com/EOF
Using Cat and EOF to replace and append files in Linux