LinuxCommandLibrary

d2u

Convert DOS/Windows text files to Unix

SYNOPSIS

d2u [options] [file ...]
d2u -n infile outfile ...

PARAMETERS

-f, --force
    Force conversion even if no DOS endings detected

-k, --keepdate
    Keep original file timestamp

-n, --newfile
    Write to <filename>.txt instead of overwriting

-q, --quiet
    Suppress all non-error messages

-v, --verbose
    Print verbose progress information

-h, --help
    Display help and exit

-V, --version
    Output version information and exit

DESCRIPTION

The d2u command converts text files from DOS/Windows format, which uses carriage return + line feed (\r\n) for line endings, to Unix/Linux format using only line feed (\n). This prevents issues like visible ^M characters or double-spacing in editors and scripts.

When processing files, d2u reads from standard input if no files are specified or if '-' is used, and writes to standard output or corresponding output files. It efficiently strips carriage returns while preserving file content. Ideal for batch-converting scripts, logs, or configs transferred via FTP, email, or shared drives between Windows and Unix systems.

Part of the dos2unix package, it supports options for safe handling, backups, and verbosity. Always test on copies for critical files, as it modifies content irreversibly unless backups are enabled.

CAVEATS

Only handles line endings, not character encoding (use iconv for UTF-8/CP1252). Avoid on binary files to prevent corruption. No built-in backup without -n.

BASIC USAGE

d2u file.txt
Converts file.txt in place.

cat windows.log | d2u > unix.log
Convert stdin to stdout.

d2u -n *.txt
Safely convert all .txt files.

HISTORY

Introduced in dos2unix package ~1989 by Harald Hannahs; modern versions (7.x) by Pedro A. Aranda GutiƩrrez since 2009, with d2u as lightweight alias.

SEE ALSO

dos2unix(1), unix2dos(1), u2d(1), fromdos(1), tr(1)

Copied to clipboard