Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to run a command recursively on all files except for those under .svn directories

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?

like image 996
zr. Avatar asked Feb 09 '10 09:02

zr.


3 Answers

Actual tested solution:

$ find . -type f \! -path \*/\.svn/\* -exec dos2unix {} \;
like image 140
Paul R Avatar answered Oct 23 '22 18:10

Paul R


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
like image 20
pixelbeat Avatar answered Oct 23 '22 18:10

pixelbeat


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.

like image 32
Tore Olsen Avatar answered Oct 23 '22 17:10

Tore Olsen