如何防止 find 打印 .git 文件夹? [英] How do I prevent find from printing .git folders?

查看:20
本文介绍了如何防止 find 打印 .git 文件夹?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 find 命令,我运行该命令来查找名称包含 foo 的文件.

I have a find command that I run to find files whose names contain foo.

我想跳过 .git 目录.下面的命令工作 except 它打印一个烦人的 .git 任何时候跳过 .git 目录:

I want to skip the .git directory. The command below works except it prints an annoying .git any time it skips a .git directory:

find . ( -name .git ) -prune -o -name '*foo*'

如何防止跳过的 .git 目录打印到标准输出?

How can I prevent the skipped .git directories from printing to the standard output?

推荐答案

试试这个:

find . -name '*foo*' | grep -v '.git'

这仍然会遍历 .git 目录,但不会显示它们.或者您可以结合您的版本:

This will still traverse into the .git directories, but won't display them. Or you can combine with your version:

find . ( -name .git ) -prune -o -name '*foo*' | grep -v '.git'

不用grep也可以:

find . ( -name .git ) -prune -printf '' -o -name '*foo*' -print

这篇关于如何防止 find 打印 .git 文件夹?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆