Bash – How to append output to the end of a text file

bashshell

How do I append the output of a command to the end of a text file?

Best Answer

Use >> instead of > when directing output to a file:

your_command >> file_to_append_to

If file_to_append_to does not exist, it will be created.

Example:

$ echo "hello" > file
$ echo "world" >> file
$ cat file 
hello
world