lf vs cr

It's really just about which bytes are stored in a file.

Follow-up on my earlier post, I wanted to find out what exactly is the difference between the two - LF vs CR.

CR is a bytecode for carriage return (from the days of typewriters) and LF similarly, for line feed. It just refers to the bytes that are placed as end-of-line markers.

CR is coded as 0x0D (13 decimal) and LF as 0x0A (10 decimal).

The two expressions have their roots in the old typewriters / TTY. LF moved the paper up (but kept the horizontal position identical) and CR brought back the “carriage” so that the next character typed would be at the leftmost position on the paper (but on the same line).

The End of Line (EOL) or CR + LF sequence (0x0D 0x0A, \r\n) is actually two ASCII characters, a combination of the CR and LF characters. It moves the cursor both down to the next line and to the beginning of that line. This character is used as a new line character in most other non-Unix operating systems including Microsoft Windows, Symbian OS and others.


Published by in May, TIL, Technical and 2017 and tagged crlf, file system and lf using 182 words.