Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I was wondering why if you open a textfile made in Windows notepad under unix you will find that it has ^M where there should be a new line?

My understanding is that in Windows, every line is ended with \r\n, ie 0x0D0A in ASCII, while ^M has ASCII value 0x5E4D. I cannot relate these two from one to the other.

share|improve this question
In Windows you can use a better editor like Notepad++. It will allow you to save the files with UNIX line endings but view it in Windows as if it had Windows line endings. Then you can view it in both OS fine. – Kevin Jul 30 '11 at 1:30
See also Jeff Atwood's take on it – nico Jul 30 '11 at 15:00
up vote 17 down vote accepted

You're right about the line endings being important; both OSes expect the line to end with "\n", but Windows also adds a "\r" before that that unix doesn't expect, so unix programs will output the "\r" in their own way.

The file doesn't actually end with the two characters "^" and "M", that's just a common way to represent unprintable characters. Programs will output "^" and a letter corresponding to the byte's value, starting with A for 1. M is the 13th letter, and '\r' is ASCII code 13 (or 0xD, as you said), so you see "^M"

share|improve this answer
That's also short-hand for Ctrl-M, which is how you get that character with the keyboard. – Steven Pritchard Jul 30 '11 at 2:31
You can use the command line utilities dos2unix and unix2dos to convert text files between formats. – Chris Nava Jul 30 '11 at 5:14
@Chris True, but doesn't really have anything to do with the question – Michael Mrozek Jul 30 '11 at 5:17
Thanks! (1) I was wondering what programs will output unprintable characters that way? For example, are all text editors/viewers work that way? (2) what kinds of unprintable characters are treated that way, and what kinds are not? For example, why don't text viewers output ^J for \n? – Tim Jul 30 '11 at 12:59
The ^M representation predates GUI text editors by years, if not decades. – Chris Nava Aug 1 '11 at 18:57

Your Answer


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.