Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

Possible Duplicate:
What's the point in adding a new line to the end of a file?

What is considered better behaviour: to leave the last letter of the last line to be the last byte of a file, or to press Enter at the end to let there be a lf? Why?

share|improve this question

marked as duplicate by Gilles, Michael Mrozek Nov 4 '11 at 14:05

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

2 Answers 2

up vote 3 down vote accepted

(Copied from my comment on the question, as requested.)

See Why should files end with a newline? - Stack Overflow. The "TL;DR": POSIX says so, and it's pretty logical to have a line end in and end-of-line character.

See the linked Stack Overflow question for practical consequences.

share|improve this answer

I always put an empty line at the end. I think it looks cleaner, and some programs choke on the last line if there isn't a newline.

share|improve this answer
    
An empty line at the end means that the file ends in two newline characters. If the file ends with a single newline character, it means the last line is not empty; the newline terminates that last line. –  Gilles Nov 3 '11 at 23:32
    
@Gilles If you want to be pedantic about it, then I what I meant was "newline". I just said "blank line" because that's the way it displays in every text editor. –  Kevin Nov 3 '11 at 23:51
    
Most unix editors do not display a blank line below a file that ends with a newline. That's not just pedantry, it's how most unix programs work. –  Gilles Nov 3 '11 at 23:56
    
Interesting, I didn't know that vim adds a newline at the end of the last line automatically. –  Kevin Nov 4 '11 at 0:11
    
@Kevin Just think of lines in a text file as records, then it's pretty logical. Pressing Enter means "begin editing a new record". When written to disk, the items in this list of lines are interspersed with newline characters. (Note that more translation is going on: Characters also must be encoded from the internal representation, for example to UTF-8) –  Jo So Sep 23 at 11:15

Not the answer you're looking for? Browse other questions tagged or ask your own question.