2017-08-08 37 views
1

(我有Ubuntu) 我的计算机上有一些git存储库。所以我想在一个命令中拥有所有的状态。 (:在find/-name ".git"为d;做CD $ d/..;回声pwd:@jmlane; git的状态;回声;完成),我发现这个答案How can I view all the git repositories on my machine?如何在没有权限的情况下查找所有.git否认消息?

但我有很多的 “权限被拒绝” 的消息。所以我搜索并找到了这个答案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 
+1

您是否尝试过使用su/sudo命令来启动它的管理权限? – vmchar

+0

可能重复的https://stackoverflow.com/questions/762348/how-can-i-exclude-all-permission-denied-messages-from-find – AllAnimals

+0

@vmchar我现在试过了:不工作 – Ccile

回答

1

这个工作罚款在我的机器上:

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

它将错误流放入特殊文件/ dev/null,这是simpy voidness。

代码:

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

正要重定向错误输出到文件命名的grep在你的工作目录。

+0

和btw它将-v设置为find的一个标志,然后find找不到该标志,并返回错误代码和错误输出'Unknown flag'。 – sudo97

+0

好吧,所以我不明白这个命令^^ 所以2>是重定向错误。而我想要推导出'权限被拒绝的错误,而不是其他错误? 为什么管道|没有工作? – Ccile

+0

由于pipe将标准输出转换为grep,所以错误输出正在手动显示。找到-name“.git”2>&1 | grep -v'权限被拒绝'在管道的情况下,在我的机器上,它首先打印关于权限被拒绝的信息,然后 - 其他信息通过grep过滤,这是逻辑的。首先发现它是工作并找到所有东西(并打印错误,因为errorstream没有重定向),然后重定向它的std输出作为grep的输入,但它已经不包含错误。我在这里给出 - 我们运行查找和重定向errorstream到std(2>&1),它也可以工作。 – sudo97

0

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

​​

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

+0

我会看到的。我不能“+1”,所以我说谢谢 – Ccile

+0

我有'locate'和'man updatedb'给了我文档,所以我想我也有。我不知道'cron'。 你给的命令不会给我同样的结果:我有一个'/ oracle。jdeveloper.git'文件,我不想拥有它,但最糟糕的是,我只有一个/.git而不是5 – Ccile

相关问题