0

I am trying to find the list of all git repositories on my local machine. I do get all of them but I also get some repositories which have Permission denied in the output

find . -name .git -type d -prune | sed '/Permission/d'

The output of the command is

find: ./.Trash/Fuze_old.app/Contents/Frameworks/Fuze Helper.app: Permission denied
./.nvm/.git
./.oh-my-zsh/.git
./.Trash/AutoLayout/.git
./.Trash/DemoProject/.git
find: ./Library/Python: Permission denied
./.Trash/NavView/.git
./.Trash/Something/.git
./.zsh/zsh-autosuggestions/.git

I do not want the lines with Permission denied.

How do I get that?

Karan Jain
  • 405
  • 1
  • 7
  • 12
  • 1
    Those probably go to stderr and you can discard them with `2> /dev/null`. – Benjamin W. Jun 13 '17 at 13:59
  • 1
    Possible duplicate of [How can I exclude all "permission denied" messages from "find"?](https://stackoverflow.com/questions/762348/how-can-i-exclude-all-permission-denied-messages-from-find) – Benjamin W. Jun 13 '17 at 14:00

1 Answers1

4

The "permission denied" lines are likely on STDERR instead of STDOUT, which is why your sed command is ineffective. Try this (if you're on a Unix-like system):

find . -name .git -type d -prune 2>/dev/null
Jonathan Leffler
  • 730,956
  • 141
  • 904
  • 1,278
Mark Adelsberger
  • 42,148
  • 4
  • 35
  • 52