如何使“find”忽略“.svn”目录?

14 浏览
0 Comments

如何使“find”忽略“.svn”目录?

我经常使用find命令来搜索源代码,删除文件等。令人烦恼的是,由于Subversion在其 .svn/text-base/ 目录中存储每个文件的副本,我的简单搜索结果会得到许多重复的结果。例如,我想在多个messages.hmessages.cpp文件中递归搜索 uint

# find -name 'messages.*' -exec grep -Iw uint {} +
./messages.cpp:            Log::verbose << "Discarding out of date message: id " << uint(olderMessage.id)
./messages.cpp:    Log::verbose << "Added to send queue: " << *message << ": id " << uint(preparedMessage->id)
./messages.cpp:                Log::error << "Received message with invalid SHA-1 hash: id " << uint(incomingMessage.id)
./messages.cpp:            Log::verbose << "Received " << *message << ": id " << uint(incomingMessage.id)
./messages.cpp:            Log::verbose << "Sent message: id " << uint(preparedMessage->id)
./messages.cpp:        Log::verbose << "Discarding unsent message: id " << uint(preparedMessage->id)
./messages.cpp:        for (uint i = 0; i < 10 && !_stopThreads; ++i) {
./.svn/text-base/messages.cpp.svn-base:            Log::verbose << "Discarding out of date message: id " << uint(olderMessage.id)
./.svn/text-base/messages.cpp.svn-base:    Log::verbose << "Added to send queue: " << *message << ": id " << uint(preparedMessage->id)
./.svn/text-base/messages.cpp.svn-base:                Log::error << "Received message with invalid SHA-1 hash: id " << uint(incomingMessage.id)
./.svn/text-base/messages.cpp.svn-base:            Log::verbose << "Received " << *message << ": id " << uint(incomingMessage.id)
./.svn/text-base/messages.cpp.svn-base:            Log::verbose << "Sent message: id " << uint(preparedMessage->id)
./.svn/text-base/messages.cpp.svn-base:        Log::verbose << "Discarding unsent message: id " << uint(preparedMessage->id)
./.svn/text-base/messages.cpp.svn-base:        for (uint i = 0; i < 10 && !_stopThreads; ++i) {
./virus/messages.cpp:void VsMessageProcessor::_progress(const string &fileName, uint scanCount)
./virus/messages.cpp:ProgressMessage::ProgressMessage(const string &fileName, uint scanCount)
./virus/messages.h:    void _progress(const std::string &fileName, uint scanCount);
./virus/messages.h:    ProgressMessage(const std::string &fileName, uint scanCount);
./virus/messages.h:    uint        _scanCount;
./virus/.svn/text-base/messages.cpp.svn-base:void VsMessageProcessor::_progress(const string &fileName, uint scanCount)
./virus/.svn/text-base/messages.cpp.svn-base:ProgressMessage::ProgressMessage(const string &fileName, uint scanCount)
./virus/.svn/text-base/messages.h.svn-base:    void _progress(const std::string &fileName, uint scanCount);
./virus/.svn/text-base/messages.h.svn-base:    ProgressMessage(const std::string &fileName, uint scanCount);
./virus/.svn/text-base/messages.h.svn-base:    uint        _scanCount;

我如何告诉find忽略 .svn 目录?


更新:如果你将你的 SVN 客户端升级到 1.7 版本 ,这将不再是一个问题。

Subversion 1.7 引入的更改的一个关键特性是将工作副本元数据存储集中在一个位置。Subversion 1.7 工作副本不再在每个目录中具有 .svn 目录,而是在工作副本的根目录中有一个 .svn 目录。该目录包括(除其他外)一个基于SQLite的数据库,其中包含Subversion需要的该工作副本的所有元数据。

admin 更改状态以发布 2023年5月24日
0
0 Comments

如下所示:

find . -path '*/.svn*' -prune -o -print

或者,基于目录而不是路径前缀:

find . -name .svn -a -type d -prune -o -print

0
0 Comments

为什么不仅仅是

find . -not -iwholename '*.svn*'

-not谓词否定了路径中任何地方都有 .svn 的所有内容。

因此在您的情况下,应该是

find -not -iwholename '*.svn*' -name 'messages.*' -exec grep -Iw uint {} + \;

0