Hany's Home Page


Hany's Dos2Unix 1.0.4 (stable release)

[Author] [ChangeLog] [Contribute] [Contributors] [Copying] [Description] [Download] [Installation] [News] [Todo] [Usage]


Peter Hanecak <hany (at) hany.sk>


Thanks to contributors:

And thanks also to suggestions from:


hd2u is Hany's DOS <-> Unix convertor.

dos2unix is filter used to convert plain texts from DOS (CR/LF) format to UNIX format (LF) and vice versa. Aditionaly it can also handle files in Macintosh format (CR) and convert them into other formats.


This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.

See the COPYING file or GNU General Public License page for license information.

Copyright 1997,.. by Peter Hanecak <hany (at) hany.sk>.
All rights reserved.


You can find sources at:

  1. http://hany.sk/~hany/_data/hd2u/

Also you can download RPM packages from:

  1. http://hany.sk/~hany/RPM/hd2u.html


First, you need some UNIX system which have some basic C development tools alredy installed.

Note: If you're using some package management tool on your system you should have also installed so called 'development' package of popt library (popt-dev or popt-devel, etc.) so required header files are also installed.

After you sucessfuly downloaded and unpacked source tarball, do the following in source directory:

$ ./configure
$ make
$ make install

This will build and install 'dos2unix' into default location, which is /usr/local/bin .

If you want to use another prefix than /usr/local use for example:

$ ./configure --prefix=/usr

This will install 'dos2unix' into /usr/bin .

For more information use:

$ ./configure --help

If you want to build optimized hd2u binary using profile-directed optimizations (gcc's -fprofile-arcs and -fbranch-probabilities options) use:

$ make dos2unix-optimized


dos2unix [--verbose|-v] [--test|-t] [--force|-f] [--<x>2<y>|--auto|-<Z>] [<file name> [...]]
--auto, -A   output will be set based upon autodetection of source format
--d2u, -U   perform DOS -> UNIX conversion
--m2u, -T   perform MAC -> UNIX conversion
--u2d, -D   perform UNIX -> DOS conversion
--u2m, -M   perform UNIX -> MAC conversion
--d2m, -O   perform DOS -> MAC conversion
--m2d, -C   perform MAC -> DOS conversion
--force, -f   suppress internal conversion type corrections based on autodetected input format
--skipbin, -b   skip binary files
--test, -t   don't write any conversion results; usefull with --verbose to just report on source type
--verbose, -v   print extra information on stderr
--version, -V   print version information on stderr

When no options are given then input format will be automatically detected and converted as follows:

Same as above applies if --auto option is used.

When no file is given, then stdin is used as input and stdout as output.

When concrete conversion type is used (--d2u or --u2d option) and file format is autodetected as target format, file is skipped - not touched - so there is no modification time change.

Binary files will be skipped automatically if option --skipbin (or -b) is used.

Stray '\r' characters (without a following '\n') are reported but only conversion 'DOS -> Unix' affects them (they are skipped).

You can display usage information using 'dos2unix -h' or 'dos2unix --help'.


How to contribute

If you would like to submit a patch, send it to me <hany (at) hany.sk>. Please be sure to include a textual explanation of what your patch does.

The preferred format for changes is 'diff -u' output. You might generate it like this:

$ cd hd2u-work
$ [your changes]
$ make mrproper
$ cd ..
$ diff -urN hd2u-orig hd2u-work > mydiffs.patch


hd2u 1.0.4

This stable release contains following changes since last stable release:

Peter Hanecak <hany (at) hany.sk>

hd2u 1.0.3

This stable release contains following changes since last stable release:

Peter Hanecak <hany (at) hany.sk>

hd2u 1.0.2

This stable release contains following changes since last stable release:

Peter Hanecak <hany (at) hany.sk>

hd2u 1.0.1

This stable release contains no functional changes since last stable release. Changes are related only to build provess:

Peter Hanecak <hany (at) hany.sk>

hd2u 1.0.0

This stable release contains no functional changes since last development release (0.9.2). Only few typos in documentation has been fixed.

Most notable changes since last stable release (0.8.2) are:

Peter Hanecak <hanecak (at) megaloman.sk>

hd2u 0.9.2

In this release issues with some binary files being recognized as text files in Macintosh format should be resolved. Also documentation has been enhanced and some typos in it fixed.

Peter Hanecak <hanecak (at) megaloman.sk>

hd2u 0.9.1

New --version (-V) option has been added to display version information and build process has been enhanced.

Peter Hanecak <hanecak (at) megaloman.sk>

hd2u 0.9.0

This release starts development period. Most notable change is addition of support for Macintosh text format.

Peter Hanecak <hanecak (at) megaloman.sk>

hd2u 0.8.2

This release introduces read/write buffers which increases conversion performance about 9 times.

Peter Hanecak <hanecak (at) megaloman.sk>

hd2u 0.8.1

Temporary files are now created in directory defined by TMPDIR or TMP environment variable. If no such variable is found, '/tmp' directory is used. Also security has been enhanced by usage of 'mkstemp()' instead of 'tmpnam()'.

Peter Hanecak <hanecak (at) megaloman.sk>

hd2u 0.8.0

This stable release consists of documentation updates and fixes.

Peter Hanecak <hanecak (at) megaloman.sk>

hd2u 0.7.2

Compilation issues with gcc 2.96 were resolved and documentation has been fixed.

Peter Hanecak <hanecak (at) megaloman.sk>

hd2u 0.7.1

In this release, there are following changes:

  1. convert() is reworked so it always "caches" input into tempfile (even when no conversion is done *). This makes dos2unix able to convert data from stdin again. Also scan/detect code has been separated from logic (conversion type selection) and verbose output. Also every conversion type (dos -> unix, unix -> dos, copy) has now its own optimised loop.

  2. From above changes comes some performance issues (I do not know if anyone cares about them, but still I'm going to write about it):

  3. As opposed to version 0.7.0, binary files are skipped only when --skipbin or -b option is used. I'm from Slovakia and our charset uses codes above 126 thus all our conversion which uses dos2unix 0.7.0 wont work on such files. So to maintain some backward compatibility from now binary files will be detected but not skipped by default.

    By the way, if you are using 'dos2unix *' you should be VERY CAREFULL!!! It's something like 'rm -rf .' if missused. So 'dos2unix *.txt *.c *.h doc/*.html' would be far better (even if not that comfortable).

  4. Rouge '\r' characters (DOS format line breaks with missing '\n' after them) are now reported but affected only by 'dos -> unix' conversion - they are skipped.

  5. If you give directory as input file to 'dos2unix' it will be skipped (I have better no idea what it was doing untill now).

Peter Hanecak <hanecak (at) megaloman.sk>

hd2u 0.7.0

This is development release based on changes from Rob Ginda <rginda (at) netscape.com> which breaks conversion functionality when converting data from stdin. So users which requires proper functionality of stdin conversion should continue to use version 0.6.0 (or earlier) and wait for fixed version to be released (or make a fix for themselves - in such case I would be happy to receive that fix :).

Peter Hanecak <hanecak (at) megaloman.sk>


1.0.4 2017/09/01
  • README, configure.in, hd2u.spec: bumped-up version
  • NEWS, hd2u.spec: added info about this release
  • use getopt from glibc instead of popt
  • packaging/hd2u.spec: converted to UTF-8
  • Makefile.in: `make clean` removes also config.h
1.0.3 2008/09/10
  • README, configure.in, hd2u.spec: bumped-up version
  • NEWS, hd2u.spec: added info about this release
  • dos2unix.c: print "stdin" instead of "(null)" in verbose mode
  • dos2unix.c: if file type is undetermined (file without line endings or empty file), print so in verbose mode and do not try to convert such file
  • Makefile.in: "$^" changed into "$(@:%=%.c)" as the "$^" gets expanded into "dos2unix.c config.h" and that causes problem for gcc 2.95.3 ("gcc: Compilation of header file requested")
1.0.2 2007/08/28
  • README, configure.in, hd2u.spec: bumped-up version
  • NEWS: added info about this release
  • dos2unix.c: added 'b' to 'fopen()' calls so that conversion is not confused on platforms like Cygwin
  • hd2us.spec: added %%{?dist} into spec
1.0.1 2007/01/28
  • README, configure.in, hd2u.spec: bumped-up version
  • NEWS: added info about this release
  • AUTHORS, README, configure.in, dos2unix.c, hd2u.spec: updated emails and URLs
  • INSTALL: added info about 'make dos2unix-optimized'
  • README: added URL for hd2u home page
  • Makefile.in: package test.sh into tarball
  • Makefile.in, hd2u.spec: 'make dos2unix-optimized' added and utilized to build hd2u optimized using profile-directed optimizations
  • Makefile.in, hd2u.spec, test.sh: implemented 'make test' to perform some basic tests of hd2u after compilation
1.0.0 2005/03/15
  • TODO: removed notice about big files being truncated
  • NEWS: added info about this release
  • NEWS: fixed few typos
0.9.2 2004/10/28
  • NEWS: updated
  • dos2unix.c: do not clear FT_BINARY flag from fileType when Mac line endings are detected which should avoid image or sound (or other binary) files to be confused with Mac text files (thanks to basic <basic (at) mozdev.org> and Caj Nordström <caj.nordstrom (at) beamex.com> for pointing out the bug and suggesting the fix)
  • README: fixed typo (thanks to N. Roeser <n-roeser (at) gmx.net> and Ryan Schmidt <hello-200407 (at) ryandesign.com> for pointing out the mistake)
  • INSTALL: added notice about popt-devel as suggested by max
  • install-sh: updated from automake-1.8.3 package
  • Makefile.in: changed '$(CC) $(CFLAGS) -o $(TARGET) $(TARGET).c $(LIBS)' to '$(CC) $(CFLAGS) -o $@ $(@:%=%.c) $(LIBS)' (based on suggestion by Marty Leisner <mleisner (at) eng.mc.xerox.com>)
  • ChangeLog, README: fixed typos
0.9.1 2004/04/14
  • Makefile.in: 'make cleanall' removes also cache directory created by 'autoconf'
  • dos2unix.c: --version (-V) option added: display version information
  • configure.in: incorporated changes sugested by configure.scan generated by 'autoscan'
  • config.h.in added (as created by 'autoheader')
  • configure.in: config.h is generated by 'configure'
  • Makefile.in: incorporated changes done to configure.in
  • README: added info about --version (-V) option
0.9.0 2003/11/14
  • dos2unix.c: files in Mac format are now recognized; thanks to Sam Barnum <sbarnum (at) pointsystems.com> and max for suggestion (and to max also for pushing me to actualy do that :)
  • dos2unix.c: new conversion types: MAC -> UNIX, UNIX -> MAC, DOS -> MAC and MAC -> DOS
  • dos2unix.c: when autodetected input format does not match input format suggested by conversion type option on command line, conversion type is automaticaly corrected
  • dos2unix.c: --force (-f) option, which supress above mentioned behaviour
  • install-sh: updated from automake-1.6 package
  • README: updated
  • TODO: what should be fixed till next stable release
0.8.2 2003/10/03
  • dos2unix.c: read/write buffers implemented - increases performance about 9 times
  • dos2unix.c: message "File format '<file>':" changed to "File format of '<file>':"
  • TODO: updated
0.8.1 2003/02/26
  • dos2unix.c: mkstemp() used instead of tmpnam()
  • dos2unix.c: temporary directory specified by TMPDIR or TMP environment variable used; if none of them is avialable, then "/tmp" is used
0.8.0 2002/05/07
  • ChangeLog: fixed typo
  • README: updated "Usage" chapter
  • dos2unix.c: updated help
  • applied patch from Philip White <pwhite (at) gigacluster.net> (minor grammar corrections and miscellaneous beautifying in help & docs)
0.7.2 2002/01/04
  • INSTALL: fixed info about changing prefix
  • Makefile.in: create bin directory before installing hd2u binary into it; this should solve the problem when using custom prefix in which 'bin' directory does not exists (thanks to Emanuele Olivetti <olivetti (at) itc.it> for reporting the problem)
  • dos2unix.c: fix gcc 2.96 warning: string length '687' is greater than the minimum length '509' ISO C89 is required to support
0.7.1 2001/01/11
  • dos2unix.c: --skipbin (-b) switch added: binary files won't be converted
  • dos2unix.c: --test (-t): NO output (not even verbose)
  • dos2unix.c: conversion of input data from stdin works again
  • dos2unix.c: reworked convert(): conversion of input data from stdin works again; better separation of detection, verbose info output and other logic
  • dos2unix.c: rouge '\r' are reported but only conversion dos -> unix affects them (they are skipped)
  • dos2unix.c: directories when given as input are skipped
0.7.0 2001/02/11
  • dos2unix.c: more robust source format detection can detect binary files, mixed mode files, and files with no line endings at all
  • dos2unix.c: added automatic skipping of binary files
  • dos2unix.c: added --test mode to check filetype without converting
  • dos2unix.c: added --verbose option to show status messages while working
  • dos2unix.c: converted C++ style (//) comments to C style (/**/) (some C compilers will choke on //)
  • dos2unix.c: reordered function definition to avoid prototypes
  • dos2unix.c: replaced hard tabs with 4 spaces
  • dos2unix.c: added emacs modeline (2001/02/07 - Rob Ginda <rginda (at) netscape.com>)
  • documentation updates (see TODO!!!)
0.6.0 2001/01/21
  • documentation: fixed typos
  • dos2unix.c: handle NULL when returned by tmpnam()
  • Makefile.in: added '-Wall -pedantic' to CFLAGS
0.5.12 2000/10/03
  • documentation extended (popt) and updated (configure)
  • configure.in: check for getopt_long() function
0.5.11 2000/09/26
  • ./configure.in: check popt library
  • Makefile.in: LIBS
0.5.10 2000/08/07
  • autoconfigure
0.5.9 2000/08/05
  • --auto option
  • do not touch files which are alredy in specified target format
0.5.0 1999/11/25
  • first public release
  • full enought feature set