Search code examples
operating-systemhistorytext-filesline-endingseol

Historical reason behind different line ending at different platforms


Why did DOS/Windows and Mac decide to use \r\n and \r for line ending instead of \n? Was it just a result of trying to be "different" from Unix?

And now that Mac OS X is Unix (-like), did Apple switch to \n from \r?


Solution

  • DOS inherited CR-LF line endings (what you're calling \r\n, just making the ascii characters explicit) from CP/M. CP/M inherited it from the various DEC operating systems which influenced CP/M designer Gary Kildall.

    CR-LF was used so that the teletype machines would return the print head to the left margin (CR = carriage return), and then move to the next line (LF = line feed).

    The Unix guys handled that in the device driver, and when necessary translated LF to CR-LF on output to devices that needed it.

    And as you guessed, Mac OS X now uses LF.