Linux dos2unix Command Tutorial

Linux and Unix operating systems use plain text for configuration etc. The Unix and MS-DOS text file formatting may have some differences which may require converting files. The MS-DOS which is Windows format used carriage return (CR) followed by Line feed (LF) are interpreted as a newline. But Linux and Unix only Line Feed (LF) is used which creates an incompatibility between Unix/Linux and MS-DOS/Windows simple text files. There are also different types of incompatibilities that are not described here. The dos2unix command can be used to convert MS-DOS/Windows simple text files into Unix/Linux simple text files.

dos2unix Command Syntax

The dos2unix command has the following syntax.

dos2unix OPTIONS SOURCE DESTINATION
  • OPTIONS are used to specify different behaivours for dos2unix command.
  • SOURCE is the source text file.
  • DESTINATION is the destination text file.

Convert From DOS to Unix Latin-1

By using following command DOS default encoding can be converted into Unix Katin-1 encoding.

$ dos2unix -iso -n source.txt destination.txt

Convert From DOS CP850 to Unix Latin-1

By using following command DOS CP850 encoding can be converted into Unix Latin-1 encoding.

$ dos2unix -850 -n source.txt destination.txt

Convert From Windows UTF-16(with BOM) To Unix UTF-8

By using following command Windows UTF-16 text file can be converted into Unix UTF-8.

$ dos2unix -n source.txt destination.txt

Keep Date and Time Stamp

The dos2unix command provides very few options. The -k option is used to keep current time stamp which means the source file filestamp is copied to the destination file.

$ dos2unix -k -n source.txt destination.txt

Leave a Comment