2

Is there such an option so that dos2unix can be applied recursively to matching files ?

yoyo
  • 57
  • 1
  • 4

3 Answers3

8

You can use find to select the files which you want to alter. And use xargs to pass filenames to dos2unix.

find . -iname '*.tpl' | xargs dos2unix

If you want to limit the search to the two directories ww1 and ww2 you can use the following command

find /var -iname '*.tpl' -regex '/var/ww[1,2]/.+' | xargs dos2unix
pacey
  • 3,833
  • 1
  • 16
  • 31
3

If you are are using zsh you can simply do:

dos2unix **/*.tpl

Which will recursively search all .tpl files for you without the need to rely on find.

Fladi
  • 860
  • 4
  • 8
  • 2
    This might cause problems depending on how much *.tpl files the poster has. If there are more files than [ARG_MAX](http://www.in-ulm.de/~mascheck/various/argmax/) this will result in an error. This problem can be avoided by using xargs. – pacey Nov 24 '10 at 09:57
0

In addition to the xargs solution, you can do find . -iname '*.tpl' -execdir dos2unix {} +. (Or just -exec on older versions of find — the end effect is the same.)

mattdm
  • 6,600
  • 1
  • 26
  • 48