How to Convert Linux Text File to Windows - Linux File Conversion

Page content

Some months ago, I had emailed the final edits for some web content to the designer, when he anxiously wrote back that he couldn’t read the text files I had sent. As the deadline was fast approaching we did some frantic digging to realize he was using Windows Notepad and I had written them on my Linux box. Strange, I thought, text files are as basic as you can get. Aren’t they all the same?

Different Line Endings

For text files, the difference between operating systems is the character used to mark the end of each line. Unix and Linux use LF (Line Feed) and DOS/ Windows use CR/LF (Carriage Return/ Line Feed). A quick way to see the type of line endings is to open a terminal and use the File command. If File reports “ASCII text” then the line endings are Unix. Instead, if it says, “with CRLF line terminators,” then the file is ready for Windows. Many Linux text editors can edit either, but that’s not always the case with Windows editors. Luckily, if you use Linux, it’s easy to change the endings.

GUI Text Editors

Two popular Linux text editors have the built-in ability to change line endings. Unfortunately, the bundled GNOME editor in Ubuntu, gedit, does not have this. Instead, try Geany, a small GTK programmer’s and text editor. To install Geany, open up a terminal and type: “sudo apt-get install geany”. Choose your desired line ending from the the Document Menu. Then save. For those who prefer KDE, the bundled editor, Kate, has the same function under the Tools menu.

Terminal Line Ending Converts

There are also Linux command line applications to convert text files. These are useful for batches of files or if you only have to make this conversion occasionally. The first is Tofrodos. To install in Ubuntu or similar, open a terminal and “type sudo apt-get install tofrodos”. The only dependency is libc6 which most likely is already installed.

Using Tofrodos is simple using the two aliased commands. To change a file from Unix to DOS, type “todos [filename]”. To change a file from DOS to Unix, type “fromdos [filename]”. The program works with pipes and accepts multiple file names and wild cards. For instance, typing “todos s*” would convert to DOS line endings all files in the current directory starting with “s”.

Tofrodos also has some useful options. To make a backup of the file before converting, use -b. If the file is read only and write permission is not granted, using the -f will still make the conversion. Unfortunately, there isn’t a recursive option, so without using other utilities, the files in each directory must be changed one at a time.

Another similar command line app is Flip. Using it is also simple, “flip -u [filename]” changes files to Unix, and “flip -m [filename]” converts the file to DOS. Like Tofrodos, Flip accepts multiple files and file name wild-cards. Install Flip in Ubuntu by typing “sudo apt-get install flip”. It has the same dependency as tofrodos.


Geany Text Editor (GTK)

Tofrodos (terminal)

Flip (terminal)

Wanting to convert Linux text files to Windows? Tolga Balci discusses how this is done using the Kate editor of KDE, or simply via the Command Line.