dos2unix on Ubuntu and Debian

DOS text files traditionally have a carriage return and line feed character as newline character or symbol – mostly for historic reasons i think. Unix and Linux on the other hand have a line feed character as newline character in text files – and Macs have yet another “standard”.

From time to time I need to convert from one text file “standard” to another.

Red Hat-based Linux distributions are normally distributed with a small tool called dos2unix, which is able to do the conversion job very easy, but Debian-based Linux distributions like Debian itself and Ubuntu do not include the dos2unix tool by default.

The dos2unix tool i available in the Debian / Ubuntu package called tofrodos. To install the packages just type:

aptitude install tofrodos

Once you have the tofrodos package installed you are able to use the dos2unix command from the command line, like this:

dos2unix dosfile.txt

After running the command all the historic and crappy windows newlines are gone. ;)

Related posts:

  1. Recursive convert dos newlines to unix ones with dos2unix
  2. Howto: Create your own Debian or Ubuntu package repository
  3. Howto: Install Ruby and Rails on Debian or Ubuntu
  4. Ubuntu Howto: Install Oracle
  5. Bash shortcuts tips and tricks
  6. Howto install Sun Java on Debian Sarge
  7. How to mount bin / cue image files in Linux
  8. Howto Install Oracle on Debian
  9. Howto: Write Debian Package Descriptions
  10. Howto: Install Windows Vista Fonts in Ubuntu

Popular Related Items »

2 Comments »

  1. Pages tagged "linux" said,

    April 30, 2008 @ 15:49

    [...] tagged linuxOwn a WordPress blog? Make monetization easier with the WP Affiliate Pro plugin. dos2unix on Ubuntu and Debian saved by 5 others     zilchnerd bookmarked on 04/30/08 | [...]

  2. Quentin said,

    July 28, 2010 @ 19:43

    I have a script that calls “dos2unix” that died because it was missing.

    Evidently, on my Ubuntu 10.4 (lucid) release, “dos2unix” and “unix2dos” are no longer in the tofrodos package, instead you have “fromdos” and “todos”.

    Since it appears in the man page that the utility detects what to do from it’s own name and still respects the “dos2unix” and “unix2dos” names, you could keep the old behaviour for your stodgy old scripts with these lines:

    sudo ln -sf /usr/bin/fromdos /usr/local/bin/dos2unix
    sudo ln -sf /usr/bin/todos /usr/local/bin/unix2dos

    But I elected to upgrade my scripts.
    – Q

RSS feed for comments on this post · TrackBack URI

Leave a Comment