\n is a line character (LF), character code 10. \r is a carriage return (CR) character, character code 13. What they do is different from system to system. On Windows, for example, lines in text files end with CR followed by LF (for example, CRLF). Unix systems and their derivatives use only LF. (Mac before Mac OS X used CR, but Mac OS X is derived from * nix and therefore uses LF.)
In the old days, LF literally did only linear feed on printers (moving down one line without moving where you are horizontally on the page), and CR similarly returned to the beginning of the line without moving paper up, so some systems (like Windows) send CR (return to the left) and LF (and feed the paper up).
Due to all this confusion, some output targets will take multiple line break sequences, so you can see the same effect from any character depending on what you output.
TJ Crowder Feb 13 '12 at 12:01 2012-02-13 12:01
source share