Linux – Why Does Linux Use LF as the Newline Character?

fileshistorynewlines

As far as I know, every operating system has a different way to mark the end of line (EOL) character. Commercial operating systems use carriage return for EOL (carriage return and line feed on Windows, carriage return only on Mac). Linux, on the other hand, just uses line feed for EOL.

Why doesn't Linux use carriage return for EOL (and solely line feed instead)?

Best Answer

Windows uses CRLF because it inherited it from MS-DOS.

MS-DOS uses CRLF because it was inspired by CP/M which was already using CRLF.

CP/M and many operating systems from the eighties and earlier used CRLF because it was the way to end a line printed on a teletype (return to the beginning of the line and jump to the next line, just like regular typewriters). This simplified printing a file because there was less or no pre-processing required. There was also mechanical requirements that prevented a single character to be usable. Some time might be required to allow the carriage to return and the platen to rotate.

Gnu/Linux uses LF because it is a Unix clone.1

Unix used a single character, LF, from the beginning to save space and standardize to a canonical end-of-line, using two characters was inefficient and ambiguous. This choice was inherited from Multics which used it as early as 1964. Memory, storage, CPU power and bandwidth were very sparse so saving one byte per line was worth doing. When a file was printed, the driver was converting the line feed (new-line) to the control characters required by the target device.

LF was preferred to CR because the latter still had a specific usage. By repositioning the printed character to the beginning of the same line, it allowed to overstrike already typed characters.

Apple initially decided to also use a single character but for some reason picked the other one: CR. When it switched to a BSD interface, it moved to LF.

These choices have nothing to do with the fact an OS is commercial or not.

1 This is the answer to your question.

Related Question