Pin Me

How to Easily Convert Linux Files to Windows

written by: rdubas•edited by: Michele McDonough•updated: 1/30/2012

The humble text file seems like it should be the same for both Linux and Windows files, but it's not. If you use Linux and regularly send other people text files for web work or source code, make sure they'll be able to read it. Here we explain how to convert Linux text files to Windows.

  • slide 1 of 1

    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.

    Resources

    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.