Having a newline character at end of file

When you create a newfile, and push it to Github, in code diff view, it will say no newline at end of file. Sometimes text editors would also add an EOF newline, if they noticed that the file being edited does not end in a newline, when they are saved (usually it is configured that way by default).

In POSIX, a line is a sequence of zero or more non-newline characters plus a terminating <newline> character. Therefore some Unix tools would expect text files to end with a newline character, especially when they process text line by line.
For example ‘wc’ will expect every line to end with a newline.


first line
second line


$ wc -l test.txt
1 test.txt

We only get one line.

This is only a concern. The modern platforms and applications we use should be ok for a text file not to end with a newline. However as long as we use the tools that would expect each line to end with a newline, we might not see all the results.


0 0 vote
Article Rating

By Sinaru Gunawardena

Sinaru is a software developer at work and a painter in free time. He enjoys writing tech notes on his personal website. He currently lives in Dublin, Ireland.

Notify of
Inline Feedbacks
View all comments