unix2dos
Convert Unix line endings to DOS format
TLDR
Change the line endings of a file
Create a copy with DOS-style line endings
Display file information
Keep/add/remove Byte Order Mark
SYNOPSIS
unix2dos [options] [file ...]
PARAMETERS
-n infile outfile
Convert infile and write to outfile. Original infile will be preserved. This is the recommended mode to avoid data corruption. This option must be the first option.
-o file
Convert file and write to file (in-place conversion). This is the default if no other options are specified.
-b
Create a backup of the original file. The backup file name is the original file name with the extension .bak.
-f
Force conversion of binary files.
-q
Quiet mode. Suppress all warnings and messages.
-u
Convert from DOS to Unix.
-h
Display help message and exit.
-V
Display version information and exit.
-L
List the currently supported file formats.
DESCRIPTION
The unix2dos command converts text files from Unix (LF line endings) to DOS/Windows (CRLF line endings) format.
Unix and DOS/Windows systems use different conventions for marking the end of a line in text files. Unix uses a single line feed (LF) character, while DOS/Windows uses a carriage return (CR) followed by a line feed (CRLF). This difference can cause issues when transferring text files between the two operating systems. For example, a text file created in Unix and opened in a Windows editor might appear as one long line. unix2dos addresses this by adding the CR character to each LF character in the file.
The command can operate in-place (modifying the original file) or can output the converted text to standard output, allowing you to redirect it to a new file. It provides options to handle various character encodings and to back up the original file before conversion.
CAVEATS
In-place conversion (-o option) can be risky if the process is interrupted or if the disk is full, as it could lead to data loss. Always consider backing up the original file, especially when using in-place conversion on important data. Be cautious when converting binary files, as it can corrupt them.
EXIT STATUS
The unix2dos command returns an exit status of 0 upon successful completion. A non-zero exit status indicates an error.
CHARACTER ENCODING
While unix2dos primarily focuses on line ending conversion, encoding issues can still arise. Ensure that both the source and destination systems use compatible character encodings (e.g., UTF-8) to avoid displaying garbled text.
HISTORY
The need for unix2dos arose from the incompatibilities in line ending conventions between Unix-like systems and DOS/Windows operating systems. Its primary purpose was to facilitate seamless transfer and viewing of text files between these platforms. Over time, it has become a standard utility found in most Linux distributions and has been refined to handle various corner cases and character encodings.