d2u
Convert DOS/Windows text files to Unix
SYNOPSIS
d2u [options] [file ...]
d2u [options] -n
PARAMETERS
-h, --help
Displays help information and exits.
-V, --version
Displays version information and exits.
-q, --quiet
Suppresses warning messages during conversion.
-k, --keepdate
Keeps the original modification date of the file after conversion.
-n, --newfile
Writes converted content to a new file instead of modifying the original. Requires the -o or --outfile option for the output filename.
-o
Specifies the name of the output file when using the -n (--newfile) option.
-c {mode}, --convmode={mode}
Sets the conversion mode. Common modes include auto (detects), dos (CRLF to LF), mac (CR to LF), and unix (LF to LF, useful for u2d).
-i, --info
Prints information about the file's line endings and Byte Order Mark (BOM) without performing conversion.
-s, --skip-error
Skips files for which conversion is not needed (e.g., already in Unix format) or where conversion fails.
DESCRIPTION
d2u (DOS to Unix) is a command-line utility used to convert text files that originate from DOS or Windows operating systems into a format compatible with Unix/Linux systems. The primary difference it addresses is the representation of line endings.
DOS and Windows use a carriage return followed by a newline character (CRLF or \r\n) to signify the end of a line, while Unix/Linux systems use only a newline character (LF or \n). This utility is crucial when transferring text files between these different environments, as files with incorrect line endings can cause scripts to fail or text editors to display extra ^M characters.
d2u reads the input file(s), identifies CRLF sequences, and replaces them with LF sequences, effectively cleaning the file for Unix consumption. It can process multiple files and often overwrites the original file or writes to standard output. It's commonly a symlink to the more comprehensive dos2unix command, providing a robust solution for cross-platform text file compatibility.
CAVEATS
d2u primarily handles line ending conversions. It typically does not address character encoding differences (e.g., ANSI vs. UTF-8) unless specifically implemented in a particular version of dos2unix. Running d2u on binary files can corrupt them, as it is designed for text file processing.
STANDARD INPUT/OUTPUT
Many implementations of d2u (via dos2unix) can read from standard input and write to standard output. This makes it highly versatile for use in shell pipelines, for example: cat input.txt | d2u > output.txt or d2u < input.txt > output.txt.
IN-PLACE CONVERSION
By default, when invoked with just a filename (e.g., d2u myfile.txt), d2u typically converts files in-place, overwriting the original file with the converted content. Users can change this behavior using options like -n or -o to specify an output file.
HISTORY
d2u is commonly found as part of the dos2unix package, which has been a standard utility on Unix-like systems for decades. It originated to solve the interoperability issues arising from different text file formats between DOS/Windows and Unix environments. The dos2unix project (which typically includes d2u and unix2dos) provides robust and actively maintained versions of these tools, handling various edge cases like Byte Order Marks (BOMs), multiple line ending styles, and preserving file attributes. It is a fundamental tool for cross-platform development and system administration.