When creating a new empty file, how do I then add a newline to it?
Running these commands:
$ touch test.txt
$ sed -i '$a\' test.txt
$ sed -i '1s/^/\n/' test.txt
$ wc -c test.txt
0 test.txt
it is clear sed had no effect.
My intention is to write to a new file which at all times has the correct permissions. Following this answer an empty file is created, but I'm having trouble editing the file non-interactively.
Using echo is not desirable, because it does not preserve permissions, as seen in this example:
$ sudo echo "text" > test.txt
$ stat -c "%U:%G" test.txt
me:mygroup