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
,-user
and-perm
flags that allow specifying type (e.g. directory vs. file), owner and permissions, respectively. Please have a good read regarding how to use-perm
as there are ways to find e.g. partial and exact permission matches.find
will descend into directories, so see if you need the-maxdepth
flag, too. – FelixJN Mar 16 '21 at 13:03filenameNEWLINEdr-x--x---
- very constructed, but it shows the limitations.find
would allow printing one character per result and skip these problems. In general the approach could work, but as saidfind
would 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:17ls
wasn't meant to be parsed by computers. – Jeff Schaller Mar 16 '21 at 13:21