如何找到所有 .git 未经许可被拒绝的消息?

How to find all the .git without permission denied message?

(我有Ubuntu) 我的计算机上到处都有一些 git 存储库。所以我想在一个命令中获得所有状态。我找到了这个答案 How can I view all the git repositories on my machine? (@jmlane : for d in find / -name ".git"; do cd $d/..; echo pwd:; git status; echo; done )

但是我有很多 "Permission denied" 消息。所以我搜索并找到了这个答案 How can I exclude all "permission denied" messages from "find"? 但我不知道如何将它添加到我的问题中。

我尝试了 find -name ".git" | grep -v "Permission non accordée" 但我得到的结果与 find -name ".git" 相同:

find: «./.cache/dconf»: Permission non accordée
find: «./.dbus»: Permission non accordée
./Documents/these/programmes/programme_ccm/.git
./Documents/these/rapports/centralisation/.git
./Documents/these/rapports/Barberis_review_2016/.git
./Documents/these/rapports/biblio/.git

我尝试了 find -name ".git" 2> grep -v "Permission non accordée" 没有结果

但是当我尝试 find -name ".git" | grep "Permission non accordée" 我得到

find: «./.cache/dconf»: Permission non accordée
find: «./.dbus»: Permission non accordée

这在我的机器上运行良好:

find -name ".git" 2> /dev/null

它将错误流放入特殊文件/dev/null,这是简单的无效性。

您的代码:

find -name ".git" 2> grep -v "Permission non accordee"

正要将错误输出重定向到您的工作目录中名为 grep 的文件。

您是否安装了 locate 软件包并且 updatedb 正在从 cron 运行?如果是,locate 是你的朋友。命令

locate -b \*.git

会比find快很多。 locate 也会自动考虑权限——输出将仅列出当前用户可访问的 .git*.git 存储库。