How to Transfer Text Files
Between
Linux, Macintosh, and Microsoft Windows
Operating Systems

Text files are often incompatible across operating systems. Why? Because different operating systems use different markers to indicate the end of a line. This can really mess you up if you are trying to transfer files from one operating system to another.

The Macintosh uses a carriage return to end a line. A carriage return marking the end of a line is intuitive to anyone who is old enough to have ever used a typewriter. For those too young to know, an electric typewriter has a big key called a carriage return that automatically advances you to the next line.

The carriage return is often referred to by the capital letters CR. On a Macintosh, every line has a CR at the end.

Under Linux (a variant of Unix), the end of a line is indicated by a line feed. Every line ends with a line feed or LF.

Calling the end of a line an LF versus a CR is not just semantics. These are 2 very real characters with 2 very real and very separate numeric representations on a computer. A CR is a 13 in the ASCII table of characters and an LF is a 10 in the ASCII table of characters.

Contributing to the confusion is that fact that Microsoft Windows does things yet another way. Under Microsoft Windows, lines end with a combination of 2 characters -- a CR followed by a LF. Symbolically, this is represented as CRLF or carriage return, line feed.

Historical Perspective

Line feeds are separate characters from carriage returns for historical reasons. In the old days, the Associated Press used to send out press releases on a machine called a teletype. Today, teletype machines appear to us as very limited because they were electro-mechanical devices and not computers.

Teletypes were big. The size and nature of the old teletypes were such that you could hear these machines tap tap taping away in the background of old radio and television newscasts. It was a sound that gave the newscast a quality of immediacy and urgency. Today, newscasts mimic this same quality of immediacy and urgency with music that opens the show.

In any case, these machines had no brain, no microprocessor, built into them. They were dumb. Being dumb machines made it necessary to tell them every little thing. Every little thing includes doing carriage returns and linefeeds.

What is a carriage return? It is the print head of the teletype moving all the way to the left side of the paper. What is a line feed? It is the platen of the teletype advancing the paper one line. These are 2 separate and distinct functions.

On typewriters, these 2 separate and distinct functions were combined into one key -- the carriage return. This is why the enter key on a computer keyboard can represent a carriage return, a line feed, or both together -- it's for historical reasons.

Converting Text Files From One Operating System to Another

Converting a text file from one operating system to another is simple in principle:

To convert a Microsoft Windows file to Linux or Macintosh file you subtract. For the conversion to a Macintosh, you subtract the LF of the CRLF combination. For the conversion to Linux, you subtract the other character -- the CR of the CRLF combination.

The reverse of subtraction is addition. To reverse direction and convert a Linux or Macintosh file to a Microsoft Windows text file, you add. For conversion from a Macintosh to Windows, you add a LF immediately following each CR. To convert a Linux file to a Windows file, you add a CR immediately before each LF.

Converting between the Macintosh and Linux is a matter of substitution rather than addition or subtraction. When going from Linux to the Mac, you substitute the LF for the CR.

Going in the opposite direction you do just the opposite: When going from the Mac to Linux, you substitute the CR for the LF.

It's Not as Hard as It Sounds

For most folks, transferring files from one operating system to another is not as hard as it sounds. Most people use FTP to transfer their files. FTP automatically does the text file conversion for you.

FTP has two basic modes for transferring files: binary mode and ASCII mode. In ASCII mode (say ask-eee), the end-of-line characters are translated for you. In binary mode, the end-of-line characters are left as-is.

Just remember this: If you are transferring text files, you want FTP to be in ASCII mode. If you are transferring anything else -- photos, drawings, sound files, etc. -- you want FTP to be in binary mode -- otherwise, you will corrupt your files by translating files that need no translating.

Summary

There are really only two characters you need to remember when transferring text files from one operating system to another -- carriage returns and line feeds. The hard part is remembering which of these characters goes where on which operating system.

There are three operating systems that make use of these 2 characters to mark the ends of lines in text files: Linux, Macintosh, and Microsoft Windows.

Both Linux and Macintosh use a single character to mark the end of a line in a text file: In the case of Linux that character is a line feed. In the case of the Macintosh, that character is a carriage return.

Microsoft Windows uses both characters to mark the end of a line. The two-character combination is a carriage return followed by a line feed.

If you use FTP in ASCII mode, all text file conversions between different operating systems are taken care of for you.

©Edward Abbott, 2002-2004. All rights reserved. Revised May 5, 2004.

Questions or comments? Email me at ed@WebSiteRepairGuy.com.

Directory of File Transfer Resources

How Do I Convert Between Unix and Mac OS

Line Breaks, Line Feeds & Carriage Returns(oh my!)

7 Reasons to Learn FTP and Learn It Well