While bash lets you easily append to a file, there's no simple way to prepend to a file.
The prepend
function provides that functionality without relying on external tools like sed
.
prepend() {
printf '%s%s' "$1" "$(< $2)" > "$2"
}
Add the function to your .bashrc
file.
$ prepend 'Text you want to prepend' path/to/file