Bash tips, tricks and code snippets

Inserting text at the beginning of a file

Based on this tip, either using sed since it can operate on a line number, in this case “1”:

sed -i '1s/^/some text to add /' FILE

or if using Bash command grouping:

{ echo -n '<some text to add> '; cat file; } > file.new
$ mv file{.new,}