Interconversion of DOS and Unix files

ASCII text files differ in one respect between DOS and Unix. In DOS, each line ends with <CR><LF> characters, whereas in Unix, lines end in <CR>. Programs that upload files, such as NetworkFileManager or FTP usually have an option that will automatically convert ASCII files. Alternatively, you can strip off the extra <LF> character using the DOS2UNIX command. To convert a file, type

dos2unix < oldfile > newfile

dos2unix will read oldfile and write a Unix version to newfile. To determine whether a file that you have uploaded is in DOS or Unix ASCII format, you can type

cat filename

If the file on Unix looks doublespaced (ie. blank lines between every text line), or each line seems to end in '^M', it is in DOS ASCII format. Similarly, if a file on DOS/Windows looks like all the characters are combined onto a single very long line, it is probably in Unix format.

On Unix, a Unix file can be converted into a DOS file by typing

unix2dos < oldfile > newfile

For more information on dos2unix type 'man dos2unix'.


Return to Using Unix