Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

Obviously there are at least two newline types: DOS and Unix. But does OS X have its own plaintext 'format'?

I opened a text file in nano and was surprised to see: [ Read 26793 lines (Converted from Mac format) ]

What is Mac format, how is it any different from a file written with a Unix tool like nano, and why does it need to be converted from to be read with nano on a Mac?

share|improve this question
add comment

2 Answers

up vote 14 down vote accepted

It should be pointed out that Mac OS X uses \n a.k.a linefeed (0x0A) now, just like all other *nix systems. Only Mac OS versions 9 and older used \r (CR).

Reference: Wikipedia on newlines.

share|improve this answer
add comment

jw013 points out in another answer that Mac has now switched to the *nix standard \n.

Previously, Mac OS was \r (carriage return, 13/0x0D); Windows is \r\n, and *nix are \n (linefeed, 10/0x0A). I'm not certain for the more obscure systems, but I'd guess nearly everything else is also \n. The difference comes from the days of the teletype when \n would move to the next line, and \r would move the head back to the start (left side) of the page, quite similar to what one had to do (manually) with a typewriter back in the day. Note that in a terminal on Linux, \r still moves the cursor to the beginning of the current line instead of moving down to the next line, consistent with its teletype use. I've seen more detailed histories on why each system chose their own line types, so I'm sure you can search for more details.

Anyway, in practical matters, most editors (except notepad) can deal with any of the three types, and there are plentiful ways to convert between them. Some remote copy tools (ftp, for instance, and probably other similar programs) even convert transparently to the correct line types for the destination when transporting files in text mode. And I read today on a SO post1 that gcc actually converts \n to the appropriate line ending for the system it's compiling on.


¹ Quote:

The varying line-ending characters don't matter, assuming the file is open in text mode, which is what you get unless you ask for binary. The compiled program will write out the correct thing for the system compiled for.

share|improve this answer
    
+1. can you share the SO Post link? –  Prince John Wesley Nov 8 '11 at 4:27
1  
You have this a bit mixed up. While you are correct that Old Mac uses '\r', Windows uses '\r\n' and Unix uses '\n' - the descriptions and hex codes you gave are incorrect. '\r' is a carriage return 0x0d / 13 and '\n' is a line feed 0x0a / 10. Reference: en.wikipedia.org/wiki/ASCII#ASCII_control_characters –  teambob Nov 8 '11 at 4:39
1  
@Kevin, nothing you said in your answer was false, but it did not in any way answer the question which was about OS X. –  Jeremy Visser Nov 8 '11 at 8:08
1  
You still haven't entirely fixed the mistake teambob pointed out: 0x0A = 10 is not the same as 0x10 = 16. Same with 0x13 not being the same as 0x0D. –  jw013 Nov 8 '11 at 19:14
1  
I disagree -- your answer was misleading. The O.P. was clearly asking about "Mac" in the context of modern OS X based machines. To state Mac line endings are \r without clarifying as "Mac OS 9 and earlier" is misleading. –  Jeremy Visser Nov 12 '11 at 15:15
show 3 more comments

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.