开发者

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

开发者 https://www.devze.com 2022-12-19 09:59 出处:网络
Here is how i run dos2unix recursively on all files: find -exec dos2unix {} \\; What do 开发者_如何学JAVAi need to change to make it skip over files under .svn/ directories?Actual tested solution:

Here is how i run dos2unix recursively on all files:

find -exec dos2unix {} \;

What do 开发者_如何学JAVAi need to change to make it skip over files under .svn/ directories?


Actual tested solution:

$ find . -type f \! -path \*/\.svn/\* -exec dos2unix {} \;


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


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.


In bash

for fic in **/*; dos2unix $fic

Or even better in zsh

for fic in **/*(.); dos2unix $fic


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
0

精彩评论

暂无评论...
验证码 换一张
取 消