One solution to the problem from prepend to a file one liner shell? is:
cat header main | tee main > /dev/null
As some of the comments noticed, this doesn't work for large files.
Here's an example where it works:
$ echo '1' > h
$ echo '2' > t
$ cat h t | tee t > /dev/null
$ cat t
1
2
And where it breaks:
$ head -1000 /dev/urandom > h
$ head -1000 /dev/urandom > t
$ cat h t | tee t > /dev/null
^C
The command hangs and after killing it we are left with:
$ wc -l t
7470174 t
What causes the above behavior where the command gets stuck and adds lines infinitely? What is different in the 1 line files scenario?