1

(I have Ubuntu) I have some git repositories here and there on my computer. So I want to have the status of all in one command. I found this answer 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 )

But I have a lot of "Permission denied" messages. So I searched and found this answer How can I exclude all "permission denied" messages from "find"? but I don't know how to addapt it to my problem.

I tried find -name ".git" | grep -v "Permission non accordée" but I have the same result as just 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

I tried find -name ".git" 2> grep -v "Permission non accordée" with no result

But when I tried find -name ".git" | grep "Permission non accordée" I obtain

find: «./.cache/dconf»: Permission non accordée
find: «./.dbus»: Permission non accordée
Ccile
  • 187
  • 1
  • 3
  • 12

2 Answers2

1

This worked fine on my machine:

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

It puts error-stream to the special file /dev/null, which is simpy voidness.

your code:

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

was about to redirect error output to file named grep in your working directory.

sudo97
  • 338
  • 1
  • 6
  • and btw it sets -v as a flag of find, and so then find doesn't know this flag, and returns error code and error output 'Unknown flag'. – sudo97 Aug 08 '17 at 14:39
  • Ok so I didn't understand this command ^^ So the 2> is to redirect the errors. And what I want to derirect just the `Permission denied`errors and not others ? Why the pipe | didn't work ? – Ccile Aug 08 '17 at 15:34
  • Because pipe takes standart output to grep, so the error output is being displayed manually. find -name ".git" 2>&1 | grep -v 'Permission denied' In case with pipe, on my machine it first prints about permission denied, and then -- the others, filtered by grep, which is logical. First find makes it's job and finds everything(and prints errors, since errorstream is not redirected), and then it redirects it's std output as input for grep, but it already doesn't contain errors. In line I give here -- we run find and redirect errorstream to std(2>&1) and it works as well. – sudo97 Aug 09 '17 at 20:56
0

Do you have locate package installed and updatedb is being run from cron? If yes, locate is you friend. The command

locate -b \*.git

will be much faster than find. Also locate takes permissions into account automatically — the output will list only .git and *.git repositories that are accessible by the current user.

phd
  • 82,685
  • 13
  • 120
  • 165
  • I have `locate` and `man updatedb` gave me the documentation so I suppose I have it too. I don't know for `cron`. The command you gave doesn't give me the same result : I have a `/oracle.jdeveloper.git` file and I don't want to have it but the worst is that I have only one /.git instead of 5 – Ccile Aug 10 '17 at 09:07