Skip to content


CR, LF, and Unix vs DOS/Windows text file formats

If you open a text file in Notepad and it all looks like one giant wrapped around line, it’s probably in Unix format.
It’s all about computer history.  In the dawn of time, computer output all used to come out of printers.  Different old operating systems told printers to go to a new line using different codes.  Unix systems all used CR (and still do).  Various other operating systems (mostly obsolete now) used LF.
  • Carriage Return or CR: move the printing head back to the beginning of the line on the left…
  • Line Feed or LF: …and move it down to the next line
When the ASCII standard was created, everybody split the difference.  The standard said you had to use both CR+LF for newlines when transferring files across the network.  Windows was just a baby then, so it adopted the new CR + LF ASCII standard for storing text files – not just transferring.
But in practice, the CR+LF standard isn’t always used for file transfers.  Sometimes files get transferred as binary files instead of ASCII text, so they’re stuck in their native Unix format.  Most text editors will fix it up for you – they’ll add the missing LFs as you open the file.  Wordpad does, for example.  But Notepad is more or less unchanged since Windows 3.1 fifteen years ago.  It doesn’t understand CR without the LF.
Believe it or not, there are stacks of different ways to store pure text files.  Big Endian vs Little Endian, ASCII/ANSI/Unicode/UTF-8/other encodings, etc etc.  But that’s the main difference you need to know.  Unix (CR for newlines) vs DOS/Windows (CR+LF for newlines).  And if you’re riveted with this history lesson: http://en.wikipedia.org/wiki/Newline

Posted in tech.