wcfind - avoid find(1) into subversion meta directories
Ben Reser contributed a bash script called wcgrep that is useful for greping in a Subversion working copy by ignoring the Subversion meta directories .svn/ and vi(m) backup files. We may find this script in the contrib/ directory in Subversion's release tar-balls. Similarly, we often need to ignore subversion meta directories when using find utility. A brute force way to throw off these directories would be post-processing by grep -v like below:
find . -ctime 1 | grep -v '/\.svn/' | grep -v '/\.svn
However, typing these two extra grep command each time is troublesome. So I wrote a Broune Shell script that wrap the concept and optimized some by using -prune like Ben Reser did. There are three key points to this script:
- Separate the first argument, the initial path argument, and the rest since we need to insert extra find commands between the path and user given find commands.
- Still need one more
grep -vpost-processing since the-prunetrick cannot remove.svn/directories. - Be sure to use
-ffor sh at the first line of this script to disable pathname expansion (noglob), or duplicated expansions will mess up the final find statement.
Like wcgrep, I call this script wcfind.sh and alias it to wcfind. Using it is easy, just like using normal find command:
wcfind . -ctime 1
And finally I can use the following command to easily moving files around like:
wcfind src/ -type f | xargs -n 1 -I @ svn mv @ ../backup/src/
If you're interested in wcfind.sh, you may find it here in my ADE project site.



One Comment
Quite useful indeed...
Do you know how to get grep itself to ignore the svn meta directories. I usually end up post-processing grep output with grep -v '\.svn/' but that gets annoying to have to type all the time.
--exclude only seems to work on filenames
Thanks,
Laurent
2 Backlinks
[...] Sorry, the comment system do not allow me to use rich-format styles. So I reply Laurent’s comment of "wcfind - avoid find(1) into subversion meta directories" here. Hi, Laurent, [...]
[...] svn-set-prop.sh 還有一個很重要的功能就是 find like filtering,至少要能夠做到依據 file name pattern 決定是否要動手。既然嘗試寫作 svn-set-prop.sh 不成,轉念一想,已經有 wcfind.sh 對 working copy 作 find like filtering 了,何不也來個工具,直接對 repository 作 find like filtering?或是乾脆整合 wcfind.sh 的功能,讓它可以吃 <repo-url> 或 <wc-path> 都可以。於是我有了 svn-find.pl,準備把合適的 find 指令全放進來。寫著寫著,才又突然發覺,直接對 repository 動刀顯然不是個好主意。別說無法反悔讓人擔憂,若是我程式寫的不好,豈不變成找到一百個檔案,就多了一百個 commit 了嗎?這確實不是個好主意。 [...]
Post a Comment