I need to get the number of directories that
- Can only be read and opened by the owner of the directory.
- Can only be opened by their group.
My current solution is this:
ls -la . | grep "^dr-x--x---" | wc -l
Is this correct? Or is there a more proper way to do this?
find- check the-type,-userand-permflags that allow specifying type (e.g. directory vs. file), owner and permissions, respectively. Please have a good read regarding how to use-permas there are ways to find e.g. partial and exact permission matches.findwill descend into directories, so see if you need the-maxdepthflag, too. – FelixJN Mar 16 '21 at 13:03filenameNEWLINEdr-x--x---- very constructed, but it shows the limitations.findwould allow printing one character per result and skip these problems. In general the approach could work, but as saidfindwould be the "proper" way you requested. Also your way does not allow optional read access - the question is not 100% clear here, if that might be allowed. – FelixJN Mar 16 '21 at 13:17lswasn't meant to be parsed by computers. – Jeff Schaller Mar 16 '21 at 13:21