38

I switched to Lion a while back and just noticed that when I save a text file in TextEdit, it uses LF for line breaks. I looked around everywhere I could think of on my Lion computer and could not find any evidence of files using CR for line breaks even though I remember that Macs always used to use CR despite Unix using LF and Windows using CR+LF. When I learned that OS X was based on Unix, I even checked on my Snow Leopard and was disappointed that it stilled used CR.

So did Lion switch to using LF?

The strangest thing is I searched all over the web and cannot find any evidence of Lion using LF.

Matt
  • 847
  • 2
  • 11
  • 24

1 Answers1

57

I remember that Macs always used to use CR despite Unix using LF and Windows using CR+LF

Your memory is from the good old times though: Mac OS X, as POSIX-compliant Unix uses the typical Unix LF.

CR is a relict from the "classic" Mac OS, it's not used anymore.

For example, check the manpage of unix2dos (emphasis mine):

In DOS/Windows text files a line break, also known as newline, is a combination of two characters: a Carriage Return (CR) followed by a Line Feed (LF). In Unix text files a line break is a single character: the Line Feed (LF). In Mac text files, prior to Mac OS X, a line break was single Carriage Return (CR) character. Nowadays Mac OS uses Unix style (LF) line breaks.

An even more authoritative reference: Shell Scripting Primer: Designing Scripts for Cross-Platform Deployment

Command-line tools in Mac OS X (and other UNIX or Linux variants) use UNIX-style line endings. This means that each line in a text file ends with a newline character (character 10/0xA, often abbreviated LF).

Many older Mac applications use "Mac-style” line endings. This means that each line in a text file ends with a carriage return character (character 13/0xD, often abbreviated CR).

slhck
  • 223,558
  • 70
  • 607
  • 592
  • I specifically remember on Snow Leopard it used CR. – Matt Jun 20 '12 at 20:03
  • 2
    I *am* on Snow Leopard and it does not use carriage returns, neither in TextEdit, TextWrangler, TextMate, vim, emacs, nano, when echoing to a file, et cetera. And there is semi-authoritative reference on that, so you must have set your editor on Snow Leopard to use carriage returns then. – slhck Jun 20 '12 at 20:06
  • 11
    I figured it out: The problem is with Microsoft Excel. When you save a CSV file on a Mac, it uses CR. – Matt Jun 20 '12 at 20:09
  • 6
    Well, talk about Microsoft software on OS X. I was aware of that problem with Excel's CSV files though, I ran into issues with that myself. – slhck Jun 20 '12 at 20:11
  • Thank you for this answer! I'm trying to add TI-89 programs to my Git repository that all end in `\r` and [Git is having trouble with it](https://stackoverflow.com/questions/57730830/how-do-i-set-r-or-cr-as-end-of-line-in-git). – NobleUplift Aug 30 '19 at 17:30
  • I'm not sure if I can help you with your question though. If it's not answered by my post, consider editing it to have it reopened. – slhck Aug 31 '19 at 12:14
  • Then what did LF do in classic Mac OS? – palapapa Mar 03 '23 at 10:00