I've tried
ls -l | cut -f1 d" " | grep ".{4}rw.{4}"
for example
drwxrwx--x folder folder 4096 sep 3 19:01 dir2
I cut off first colomn and find match with "rw"
but nothing happens
CodePudding user response:
When searching for files by name, size, or other properties you can't go wrong with find
. For your use case try -perm -{mode}
, which finds files with all of the {mode}
bits set. You can use a numeric mode like 030
or the symbolic version, g=rw
:
find * -perm -g=rw # search subdirectories
find * -maxdepth 0 -perm -g=rw # current directory only
Here's the full description of the different -perm
options from the find(1) man page:
-perm mode File's permission bits are exactly mode (octal or symbolic). Since an exact match is required, if you want to use this form for symbolic modes, you may have to specify a rather complex mode string. For example `-perm g=w' will only match files which have mode 0020 (that is, ones for which group write permission is the only permission set). It is more likely that you will want to use the `/' or `-' forms, for example `-perm -g=w', which matches any file with group write permission. See the EXAMPLES section for some illustrative examples. -perm -mode All of the permission bits mode are set for the file. Symbolic modes are accepted in this form, and this is usually the way in which you would want to use them. You must specify `u', `g' or `o' if you use a symbolic mode. See the EXAMPLES section for some illustrative examples. -perm /mode Any of the permission bits mode are set for the file. Symbolic modes are accepted in this form. You must specify `u', `g' or `o' if you use a symbolic mode. See the EXAMPLES section for some illustrative examples. If no permission bits in mode are set, this test matches any file (the idea here is to be consistent with the behaviour of -perm -000).