Differences between carriage return and line feed

Source: Internet
Author: User

Carriage Return and line feed

Press enter \ r, line feed \ n



The origins and differences between carriage return and line feed.

Before the computer appeared, there was a kind of device called teletype model 33, which can contain 10 characters per second. But there is a problem, that is, when a line breaks a line, it takes 0.2 seconds, just two characters. If a new character is passed in the 0.2 s, the character will be lost.

As a result, the developers thought of a way to solve this problem, that is, adding two end characters after each line. One is "enter", which tells the typewriter to position the print head on the left boundary, and the other is "line feed", which tells the typewriter to move the paper down one line.

This is the source of "line feed" and "Carriage Return". They can also be seen in their English names.

Later, computers were invented, and these two concepts were invented on computers. At that time, memory was very expensive. Some scientists thought it would be too waste to add two characters at the end of each line. Just add one character. As a result, there were differences.

In Unix systems, each line ends with "<line feed>", that is, "\ n". In Windows systems, each line ends with "<press enter> <line feed> ", that is, "\ r \ n". In MAC systems, the end of each line is "<press enter> ". One direct consequence is that if a file in UNIX/MAC is opened in windows, all the text will be changed to a line; if a file in Windows is opened in UNIX/MAC, A ^ m symbol may be added at the end of each line.



Next, let's take a look at the actual operation results in Linux. Text that combines a line feed (\ n, 0x0a) and a carriage return (\ r, 0x0d ).
$ Echo-en'12 \ n34 \ R56 \ n \ R78 \ r \ n'> TMP
View text in hexadecimal format
0000000 31 32 0a 33 34 0d 35 36 0a 0d 37 38 0d 0a

Display Results in VIM in Linux

Display Effect in Windows notepad

It can be seen that in Linux, the carriage return + line feed operation will be performed when a line break is encountered. Instead, the carriage return will only be displayed as a control character without the carriage return operation. In Windows, carriage return and line feed are required before carriage return and line feed are performed. If a control character is missing or the order is incorrect, a new line cannot be entered.

From: http://www.360doc.com/content/10/0512/13/1404032_27214993.shtml

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.