dos2unix / unix2dos - Text file format converters

Convert text files with DOS or Mac line breaks to Unix line breaks and vice versa.

|dos2unix| unix2dos| contact| https://waterlan.home.xs4all.nl/|

History

This is an update of Benjamin Lin's implementations of dos2unix and unix2dos. Benjamin Lin's implementations of dos2unix and unix2dos were distributed via SunSITE.unc.edu (later MetaLab.unc.edu, now ibiblio) and became part of several Linux distributions such as RedHat, Suse, Gentoo, and others. This update includes all RedHat patches and fixes several other problems. Internationalization has been added and ports to DOS, Windows, Cygwin and OS/2 Warp have been made.

These implementations of dos2unix and unix2dos have been modelled after dos2unix/unix2dos under SunOS/Solaris. The first versions were made by John Birchfield in 1989, and in 1995 rewritten from scratch by Benjamin Lin. Mac to Unix conversion was added by Bernd Johannes Wuebben in 1998, Unix to Mac conversion by Erwin Waterlander in 2010.

In 2010 the two separate dos2unix and unix2dos packages have been bundled into a single dos2unix package (version 5.0). Support for Unicode UTF-16 was added in 2012 (version 6.0). Version 7.0, in 2014, was a major code cleanup and added a test suite.

Features

Latest version: 7.5.2 (2024-01-22)

Stable version: 7.5.2 (2024-01-22)

News

2024-01-22: Version 7.5.2 Dos2unix can print info about the line break type of the last line, or indicate there is none. Updated documentation about the ASCII conversion mode.
2023-08-29: Version 7.5.1 Fixed problem of converting a symbolic link target that is on another file system. Updated Chinese and Serbian translations.
2023-05-17: Version 7.5.0 New option -e, --add-eol to add a line break to the last line if there isn't one. New option -O, --to-stdout to write to standard output.
2023-02-11: Version 7.4.4 New Catalan, Georgian, Romanian, and Korean translations of the UI messages. New Korean and Romanian translations of the manual.
2022-06-05: Version 7.4.3 New Serbian translation of the manual. Updated Esperanto translation.
2020-10-12: Version 7.4.2 New Friulian tranlation. Updated Dutch, German, Serbian, Traditional Chinese, and Ukrainian translations.
2019-09-24: Version 7.4.1 Updated Danish, German, Hungarian, Japanese and Ukranian translations. Code cleanup.
2017-10-10: Version 7.4.0 New option --allow-chown to allow file ownership change in old file mode.
2017-07-04: Version 7.3.5 New flag 0 for option -i to end printed lines with a null character to enable correct file name interpretation when flag c is used. Don't print leading spaces when option -i with flag c is used. Manual updates. Translation updates. Code cleanup. Fixed compilation for MSYS2.
2016-05-24: Version 7.3.4 Safer creation of temporary file on Windows. Code cleanup. Update translations.
2016-02-13: Version 7.3.3. New flags h (print header) and p (remove path from file name) for option -i, --info. Fixed printing text in unicode UTF-16 mode on Windows, so that when it is redirected to a file, a correct UTF-16 file is created. Fixed printing of East-Asian text on Windows with an East-Asian regional setting.
2015-12-27: moved git repo. To clone the repo type: git clone https://git.code.sf.net/p/dos2unix/dos2unix
2015-12-20: dos2unix moved to git. The dos2unix source code repository moved from Subversion to Git.
2015-11-20: Version 7.3.2. New Swedish translations of messages and manual. Updated Danish and Brazilian Portuguese translations. Fix option -iso. The -iso option was misinterpreted as a corrupted -i option. Fix compilation for MSYS1 (mingw.org).
2015-09-30: Version 7.3.1. New simplified Chinese translation of the messages and manual. Fixed compile error "wchar_t undefined" when Unicode support is disabled. Fix compilation for MinGW (mingw.org). MinGW-w64 was OK.
2015-08-24: Version 7.3. New: Unicode file name support on Windows. Fix: Options -ul and -ub caused option -i to report wrong BOM for no_bom.
2015-07-01: Version 7.2.3. Fix: Check for file I/O errors while reading input files, and added a few missing checks while writing output files. Fix compilation for msys.
2015-05-22: Version 7.2.2. Check UTF-16 for invalid surrogate pairs. Print system error and line number when UTF-16 conversion error occurs. Bug fix: When conversion of an UTF-16 file with binary symbols was forced, null characters were not written in the output. Fixed symlink support on FreeBSD.
2015-04-01: Version 7.2.1. Skip GB18030 test when zh_CN.gb18030 locale is not supported. Fix test for option -f. Update manual, section GB18030, and option -m.
2015-02-11: Version 7.2. New Japanese translation of the UI messages. Support Chinese GB18030 locale. On Unix/Linux convert UTF-16 to the locale encoding. It is no longer required that the locale encoding is UTF-8.
2014-10-06: Version 7.1. New option -i, --info, display file information. This new option prints number of line breaks (DOS Unix Mac), the byte order mark, and if the file is text or binary. It can also print the names of files that would be converted.
2014-09-09: Version 7.0. New option -u: Keep UTF-16 encoding of input file. New option -v: Verbose. Print extra information about amount of converted line breaks and BOMs. New self-tests. Stdio mode does not automatically set quiet option and does not automatically force conversion of binaries. Code cleanup.

dos2unix - text file format converters

includes:
dos2unix - DOS/Mac to Unix text file format converter (dos2unix/mac2unix)
unix2dos - Unix to DOS/Mac text file format converter (unix2dos/unix2mac)

Wanted: translators.
If you want to help translating the dos2unix messages into more languages go to the Translation Project.
Translation of UI messages here
Translation of manual here

NEWS.txt Basic change log.
ChangeLog Detailed change log.

dos2unix manual
Chinese simplified (中文)
Dutch (Nederlands)
English
French (français)
German (Deutsch)
Korean (한국어)
Polish (polski)
Portuguese (Brazilian) (Português do Brasil)
Romanian (Română)
Serbian (српски)
Spanish (español)
Swedish (svenska)
Ukrainian (український)

COPYING.txt Distribution license, FreeBSD (GPL compatible)
TODO.txt Things to do.
BUGS.txt Known bugs and instructions on reporting new ones.
README.txt General information.
INSTALL.txt Instructions how to build dos2unix yourself.
DEVEL.txt Information about dos2unix' implementation choices.
DONATE If you want to give something back.

Source code
dos2unix-7.5.2.tar.gz Source code, Unix text.
dos2unix-7.5.2.tar.gz.asc PGP key.
d2u752.zip Source code, DOS text.

Ready-to-run binaries

Old versions.

Latest version

dos2unix-7.5.2-beta3.tar.gz Source code (Unix text)
d2u752b3.zip Source code (DOS text).

Recursive conversion of files

To recursively convert text files in a directory tree, use dos2unix in combination with the 'find' and 'xargs' commands. For instance to convert all .txt files under the current directory type:

find . -name '*.txt' |xargs dos2unix

Windows users can use the following command in a Windows Command Prompt:

for /R %G in (*.txt) do dos2unix "%G"

See also here for more information about the "for /R" command.

PowerShell users can use the following command in a Windows PowerShell:

get-childitem -path . -filter '*.txt' -recurse | foreach-object {dos2unix $_.Fullname}

Drag & drop file info

This batch script d2uinfo.bat can be copied to the Desktop. You can drag & drop files into it to get file information about number of line breaks, byte order mark, and text/binary. (Thanks to Alan S. Jones)

@ECHO OFF
ECHO.
call dos2unix -ihp %*
ECHO.
pause

Manual pages SunOS versions

SunOS dos2unix man page
SunOS unix2dos man page

Distributions including this version of dos2unix

openSUSE see here.
Fedora Linux, here (rpmfind.net) or "sudo dnf install dos2unix"
Mageia Linux. here
Arch Linux package, look here.
Slackware package here.
Gentoo Linux provides dos2unix in its package repository. See here
Debian Linux. See here.
Ubuntu Linux (universe). See here. "sudo apt-get install dos2unix"
Linux Mint. See here.
Kali Linux. See here.
Fink project, Darwin and Mac OS X. See here.
MacPorts portfile. See here.
HomeBrew Formulae. See here.
NetBSD Packages Collection. See converters/dos2unix.
FreeBSD. See FreshPorts and FreeBSD Ports.
Cygwin. See https://cygwin.com/. Install with Cygwins' setup.exe. Utils/dos2unix.
MSYS2. See https://www.msys2.org/. pacman -S dos2unix
MSYS/MinGW. See https://osdn.net/projects/mingw/. Install with "mingw-get install msys-dos2unix" or "mingw-get install mingw32-dos2unix"
FreeDOS. See http://www.freedos.org/. See here for the files in the FreeDOS distribution.

Source code libintl DLL

The win32 binaries are packaged with with a patched version of MinGW's libintl DLL that has builtin relocation support. See https://waterlan.home.xs4all.nl/libintl.html

unix2dos - Unix to DOS text file format converter

Since version 5.0 (2010-02-16) is unix2dos included in the dos2unix package. The separate unix2dos package is now obsolete.

Development

SourceForge project page : https://sourceforge.net/projects/dos2unix/

Latest development version from Git repository:

git clone https://git.code.sf.net/p/dos2unix/dos2unix
Browse the code here

Check the files out as-is (no line break conversion), otherwise tests will fail.

Alternative implementations

Tofrodos by Christopher Heng
hd2u: Hany's Dos2Unix by Peter Hanecak
CygUtils contains "conv", a heavily modified version of hd2u.
DOS2UNIX/UNIX2DOS by Clem Dye
Flip by Craig Stuart Sapp
Flip by Rahul Dhesi.
Flip by James R. van Zandt/Rahul Dhesi.
TRCH by James Hall (FreeDos)
unix2dos by Angelo Campagnari
dtou/utod Part of DJGPP's development kit.
strp by Eddie Buckley
u2d by Liam C. Drew
xchange by Amin Hamdan
dos2unix by Alain. Written in Delphi 3.
dos2unix/unix2dos by BestCode. Part of File Utilities tool set (commercial)
Endlines by Mathias Dolidon
nws-cli by Michael Klement

Contact

Erwin Waterlander