views:

349

answers:

5

Here is how i run dos2unix recursively on all files:

find -exec dos2unix {} \;

What do i need to change to make it skip over files under .svn/ directories?

A: 

In bash

for fic in **/*; dos2unix $fic

Or even better in zsh

for fic in **/*(.); dos2unix $fic
yogsototh
How does this skip `.svn/` directories?
Nathan Fellman
if dotglob is off, it will skip hidden files. But other hidden files will also be skipped, which i think is not what OP wants.
ghostdog74
Oooops, sorry!for root in {*,.*}(N); do [[ $root = .svn ]] for fic in $root/**/*(.); do dos2unix $fic ;done;works but the find version is better now...
yogsototh
+1  A: 

Just offering an additional tip: piping the result through xargs instead of using find's -exec option will increase the performance when going through a large directory structure if the filtering program accepts multiple arguments, as this will reduce the number of fork()'s, so:

find <opts> | xargs dos2unix

One caveat: piping through xargs will fail horribly if any filenames include whitespace.

Tore Olsen
`find ... -print0 | xargs -0 ...` handles filenames with spaces.
Dennis Williamson
A: 
find . -path ./.svn -prune -o -print0   | xargs -0 -i echo dos2unix "{}" "{}"

if you have bash 4.0

shopt -s globstar
shopt -s dotglob
for file in /path/**
do
  case "$file" in
    */.svn* )continue;;
  esac
  echo dos2unix $file $file
done
ghostdog74
This one doesn't seem to work either.
Paul R
Changing -path ./.svn to -path '*/.svn' should fix it.
Juris
`-i` is deprecated, use `-I{}` instead. Also, why two `"{}"`?
Dennis Williamson
+5  A: 

Actual tested solution:

$ find . -type f \! -path \*/\.svn/\* -exec dos2unix {} \;
Paul R
thanks, worked ok for me.
zr
+2  A: 

Here's a general script on which you can change the last line as required. I've taken the technique from my findrepo script:

repodirs=".git .svn CVS .hg .bzr _darcs"
for dir in $repodirs; do
    repo_ign="$repo_ign${repo_ign+" -o "}-name $dir"
done

find \( -type d -a \( $repo_ign \)  \) -prune -o \
     \( -type f -print0 \) |
xargs -r0 \
dos2unix
pixelbeat