11

I am looking for a command that I could use to run on an entire directory and subdirectory that will convert all line endings from DOS to UNIX.

It should be able to detect if a file is text or binary.

I installed dos2unix using macports but it looks that it does miss the recursive option.

  • Define how a file is text or binary? – user151019 Jun 8 '14 at 13:02
  • Text: No ASCII below 32, except for TAB, CR, LF. – Max Ried Jun 8 '14 at 13:07
22

Try find . -name "*" -type f -exec dos2unix {} \;.


In case dos2unix is not available on your system, you can use the following script (save as dos2unix and set as executable):

#!/bin/sh

perl -pi -e 's/\r\n/\n/;' $*
  • Don't run this command in the root of a Git repository or else you'll ruin your repository! – Nick Dec 5 '13 at 6:15
  • Also, I had better luck using perl -pi -e 's/\r\n|\n|\r/\n/;' $* (source) – Nick Dec 6 '13 at 4:58
1

Here is one line shell code find . -name "*" -type f -exec perl -pi -e 's/\r\n/\n/;' {} \;

  • One line answers are discouraged. Try adding more detail, or comment on it. – Max Ried Jun 8 '14 at 15:21
  • Works as advertised ! What else to add ? ;-) – Taiko Apr 18 '15 at 8:55
  • 2
    Hm... well it did screw up some png files though. Handle with care – Taiko Apr 18 '15 at 9:01

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .