Note that there are some explanatory texts on larger screens.

plurals
  1. POHow can I get `find` to ignore .svn directories?
    primarykey
    data
    text
    <p>I often use the <code>find</code> command to search through source code, delete files, whatever. Annoyingly, because Subversion stores duplicates of each file in its <code>.svn/text-base/</code> directories my simple searches end up getting lots of duplicate results. For example, I want to recursively search for <code>uint</code> in multiple <code>messages.h</code> and <code>messages.cpp</code> files:</p> <pre><code># find -name 'messages.*' -exec grep -Iw uint {} + ./messages.cpp: Log::verbose &lt;&lt; "Discarding out of date message: id " &lt;&lt; uint(olderMessage.id) ./messages.cpp: Log::verbose &lt;&lt; "Added to send queue: " &lt;&lt; *message &lt;&lt; ": id " &lt;&lt; uint(preparedMessage-&gt;id) ./messages.cpp: Log::error &lt;&lt; "Received message with invalid SHA-1 hash: id " &lt;&lt; uint(incomingMessage.id) ./messages.cpp: Log::verbose &lt;&lt; "Received " &lt;&lt; *message &lt;&lt; ": id " &lt;&lt; uint(incomingMessage.id) ./messages.cpp: Log::verbose &lt;&lt; "Sent message: id " &lt;&lt; uint(preparedMessage-&gt;id) ./messages.cpp: Log::verbose &lt;&lt; "Discarding unsent message: id " &lt;&lt; uint(preparedMessage-&gt;id) ./messages.cpp: for (uint i = 0; i &lt; 10 &amp;&amp; !_stopThreads; ++i) { ./.svn/text-base/messages.cpp.svn-base: Log::verbose &lt;&lt; "Discarding out of date message: id " &lt;&lt; uint(olderMessage.id) ./.svn/text-base/messages.cpp.svn-base: Log::verbose &lt;&lt; "Added to send queue: " &lt;&lt; *message &lt;&lt; ": id " &lt;&lt; uint(preparedMessage-&gt;id) ./.svn/text-base/messages.cpp.svn-base: Log::error &lt;&lt; "Received message with invalid SHA-1 hash: id " &lt;&lt; uint(incomingMessage.id) ./.svn/text-base/messages.cpp.svn-base: Log::verbose &lt;&lt; "Received " &lt;&lt; *message &lt;&lt; ": id " &lt;&lt; uint(incomingMessage.id) ./.svn/text-base/messages.cpp.svn-base: Log::verbose &lt;&lt; "Sent message: id " &lt;&lt; uint(preparedMessage-&gt;id) ./.svn/text-base/messages.cpp.svn-base: Log::verbose &lt;&lt; "Discarding unsent message: id " &lt;&lt; uint(preparedMessage-&gt;id) ./.svn/text-base/messages.cpp.svn-base: for (uint i = 0; i &lt; 10 &amp;&amp; !_stopThreads; ++i) { ./virus/messages.cpp:void VsMessageProcessor::_progress(const string &amp;fileName, uint scanCount) ./virus/messages.cpp:ProgressMessage::ProgressMessage(const string &amp;fileName, uint scanCount) ./virus/messages.h: void _progress(const std::string &amp;fileName, uint scanCount); ./virus/messages.h: ProgressMessage(const std::string &amp;fileName, uint scanCount); ./virus/messages.h: uint _scanCount; ./virus/.svn/text-base/messages.cpp.svn-base:void VsMessageProcessor::_progress(const string &amp;fileName, uint scanCount) ./virus/.svn/text-base/messages.cpp.svn-base:ProgressMessage::ProgressMessage(const string &amp;fileName, uint scanCount) ./virus/.svn/text-base/messages.h.svn-base: void _progress(const std::string &amp;fileName, uint scanCount); ./virus/.svn/text-base/messages.h.svn-base: ProgressMessage(const std::string &amp;fileName, uint scanCount); ./virus/.svn/text-base/messages.h.svn-base: uint _scanCount; </code></pre> <p>How can I tell <code>find</code> to ignore the <code>.svn</code> directories?</p> <hr> <p><strong>Update</strong>: If you upgrade your SVN client to <a href="http://subversion.apache.org/docs/release-notes/1.7.html#single-db" rel="noreferrer">version 1.7</a> this is no longer an issue.</p> <blockquote> <p>A key feature of the changes introduced in Subversion 1.7 is the centralization of working copy metadata storage into a single location. Instead of a <code>.svn</code> directory in every directory in the working copy, Subversion 1.7 working copies have just one <code>.svn</code> directory—in the root of the working copy. This directory includes (among other things) an SQLite-backed database which contains all of the metadata Subversion needs for that working copy.</p> </blockquote>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. COFor performance, try to use `find ... -print0 | xargs -0 egrep ...` instead of `find ... -exec grep ...` (does not fork `grep` for each file, but for a bunch of files at a time). Using this form you can also prune `.svn` directories without using the `-prune` option of find, i.e. `find ... -print0 | egrep -v '/\.svn' | xargs -0 egrep ...`
      singulars
    2. CO@Vlad: As far as I know, using `-exec` with `+` doesn't fork `grep` for each file, while using it with `;` does. Using **`-exec`** is actually **more correct** than using `xargs`. Please notice that commands like `ls` do something even if the argument list is empty, while commands like `chmod` give an error if there is insufficient arguments. To see what I mean, just try the following command in a directory that does not have any shell script: **`find /path/to/dir -name '*.sh' -print0 | xargs -0 chmod 755`**. Compare with this one: **`find /path/to/dir -name '*.sh' -exec chmod 755 '{}' '+'`**.
      singulars
    3. CO@Vlad: Besides, `grep`-ing out `.svn` is not a good idea too. While `find` is specialized for handling file properties, `grep` does not. In your example, a file named **'.svn.txt'** will also be filtered by your `egrep` command. Although you can modify your regex to **'^/\.svn$'**, it is still not a good practice to do so. The **`-prune`** predicate of **`find`** works perfectly for filtering a file (by filename, or creation timestamp, or whatever condition you supplied). It is just like even if you can kill a cockroach using a big sword doesn't mean it is the suggested way to do so :-).
      singulars
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload