Cr, lf, CR/LF carriage return to favorites

Source: Internet
Author: User
Tags ftp client

The origins and differences between carriage return and line feed.

Not on the computer
Before the appearance, there was a teletype Model
33. The tty concept in Linux/Unix also comes from this). It can contain 10 characters per second. However, the problem is that it takes 0.2 seconds to finish a line break
It can be two characters long. 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 only "<line feed>", that is, "\ n". In Windows systems, each line ends with "<line feed> <press ENTER
> ", That is," \ n \ r ". In MAC systems, the end of each line is" <press enter> ", that is," \ r ";. One direct consequence is that files in UNIX/MAC systems are stored in
If it is opened in windows, all the text will become one line. If the files in windows are opened in UNIX/Mac, there may be an extra ^ m symbol at the end of each line.

In text processing, Cr, lf, CR/LF are linefeeds used on different operating systems.
DOS and Windows use carriage return + line feed Cr/LF to represent the next line,
In Unix/Linux, the line break lf indicates the next line,
The Mac OS system uses the carriage return (CR) to indicate the next line.
Cr is represented by the '\ R' symbol, in ASCII notation.CodeIs 13, and the hexadecimal code is 0x0d;
Lf uses the '\ n' symbol. the ASCII code is 10 and the hexadecimal value is 0x0a.
Therefore, on Windows, line breaks are represented by 0d 0a in text files, while on UNIX and Apple platforms, line breaks are represented by 0a or 0d in one byte.
Generally, the Runtime library on the operating system automatically determines the line feed format of text files. For exampleProgramRun on Windows to generate a text file in CR/LF line feed format, and run on Linux to generate a text file in LF format line feed.
Using another line break file on one platform may cause unexpected problems, especially when editing program code. sometimes the code is displayed normally in the editor, but an error occurs due to line breaks during editing.
Many text/code Editors Use the line break Conversion Function to swap line breaks in text files in different formats.
When FTP software is used to transfer files between different platforms, some FTP client programs automatically convert the line feed format in ASCII text transmission mode. the number of bytes transmitted may change. if you do not want to modify the original file via FTP, you can use bin mode (binary mode) to transfer text.

 

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.