I'm searching for all files that contain one of a set of strings. If they do, I change their access rights.
find . -type f -exec grep -q '#!/bin/bash\|#!/usr/bin/grep\|#!/usr/bin/awk' {} \; -exec chmod 700 {} ;\
I'm curious how the find works when it finds a file containing that string grep -q
gives me 0
so another exec executes but should not. That second exec
finds all files and change the rights to all files. Why does it work and change only those files containing that string?
... -exec grep -E -q '#! *(/usr)?(/local)?/bin/([bd]ash|[zk]sh|t?csh|awk|sed|perl)' ...
(note: I removed the pattern that matches/usr/bin/grep
because that makes no sense, grep is not a scripting language. Added dash, zsh, ksh, tcsh/csh, sed and perl instead).#!
makes more sense than trying to guess al possible interpreters.#!
is both at the start of the line, AND is the first line of the file.