2017-08-08 174 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

相關問題