linux - Stat with find not excluding files -


within bash script, trying find files based on octet using stat in combination find, want skip files (file1, file2, etc.). doesn't appear working. why , how can fix it? best way of doing this?

$(stat --format %a 2>&1 $(find /example/dir -type f -not \( -name 'file1' -o \        -name 'file2' -o -name 'file3' -o -name 'file4' \) -prune) | egrep "777|755" 

original question — 777 permission only

if looking files 777 permission, use find that:

find /example/dir -type f -perm 777 

if don't want include file1, file2, file3 or file4 in output, use grep too:

find /example/dir -type f -perm 777 | grep -ev 'file[1234]' 

if want output stat files, then:

find /example/dir -type f -perm 777 | grep -ev 'file[1234]' | xargs stat --format %a 

or:

stat --format %a $(find /example/dir -type f -perm 777 | grep -ev 'file[1234]') 

this more run problems if list of files huge. can reinstate -prune option on of find commands require. however, running find example/dir -type f , find example/dir -type f -prune made no difference result saw.

revised question — 777 , 775 permission

if you're looking 777 or 775 permission, need:

find /example/dir -type f -perm +775 

this happens work because there's 1 bit different between 777 , 775 permissions. more general , extensible solution use -or operations:

find /example/dir -type f \( -perm 777 -or -perm 775 \) 

with changes in numbers, 664 or 646 permission without picking executable files, -perm +622 pick up.

problems in question code

as going wrong code in question — not sure.

$ find example/dir -type f example/dir/a/filea example/dir/a/fileb example/dir/b/filea example/dir/b/fileb example/dir/c/filea example/dir/c/fileb example/dir/filea example/dir/fileb $ find example/dir -type f -not \( -name filea -o -name fileb \) $ find example/dir -type f -not \( -name filea -or -name fileb \) $ find example/dir -type f \( -name filea -or -name fileb \) example/dir/a/filea example/dir/a/fileb example/dir/b/filea example/dir/b/fileb example/dir/c/filea example/dir/c/fileb example/dir/filea example/dir/fileb $ find example/dir -type f ! \( -name filea -or -name fileb \) $ find example/dir -type f \( -not -name filea -and -not -name fileb \) $  

the -not or ! operator seems mess things up, i'd not expect. superficially, looks bug, i'd have have lot more evidence , have lot of careful scrutiny of find specification before claimed 'bug'.

this testing done find on mac os x 10.8.3 (bsd), no gnu find.

(your use of term 'octet' in question puzzling; used indicate byte in network communications, more stringent meaning precisely 8 bits byte need not be. permissions presented in octal , based on 16 bits, 2 octets, in inode.)


Comments

Popular posts from this blog

blackberry 10 - how to add multiple markers on the google map just by url? -

php - guestbook returning database data to flash -

delphi - Dynamic file type icon -