I sometimes whether I should put a newline after the last line in a configuration file, especially if it is a one-line configuration file, like the hostname file.

Does it not matter, or is there a rule?

  • It's useful if you want to append to it.
    – Ben
    Nov 29, 2018 at 0:55
  • See unix.stackexchange.com/q/18743/185953
    – Ben
    Nov 29, 2018 at 0:57
  • it is unclear what you are asking ......are you talking about a file that has two newlines at the end, one at end of line and a second one after that line? ..... are you talking about only one newline at the end? .... are you talking about no newline at the end?
    – jsotola
    Nov 30, 2018 at 2:48

1 Answer 1


Yes, the last character of a valid POSIX text file must be a newline.
It has been debated before.
It is easy (and very fast) to correct a file (if needed).
And vim might be configured to automatically ensure that a trail newline is included.

It matters in the sense that some tools expect a text file, and therefore expect an ending newline. For example the shell read will fail (unless configured in a special way) to read the last line of a text file that is missing a newline. And concatenation of files with cat will also require special handling.

You can not follow the recomendations to reduce one byte per file, but at the cost of added complexities to process files. It is not worth the trouble IMO.

I can not think of any other reason to avoid having an ending newline for a text file.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .