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

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

问题描述

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

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

我想跳过 .git 目录.下面的命令除外有效,它会打印一个每次跳过 .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:

You can also do it without grep:

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

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

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