6

I've looking for a way to express this command that excludes all executable perms except for those files ended in ".EXE"

I've trying to solve it using the "find" command and -exec, please. Thanks.

The command I tryed, and other versions of the same, does not work:

find . -type f -regex "[^\.EXE$]" -printf "%f\n" -exec chmod a-x {} +

Thanks any help, Beco.


Edited:

To find a "inverse" of a regular expression, I tried after (more) research:

find . -type f ! -regex ".EXE$" -printf "%f\n" -exec chmod a-x {} +

But this also did not work.

DrBeco
  • 11,237
  • 9
  • 59
  • 76
  • 1
    If you want to use -regex predicate, not the -name predicate, you need to specify a regular expression, that matches the whole name: -regex ".*\.EXE$" – Dima Chubarov May 03 '12 at 18:24

3 Answers3

10

There are few things that can be fixed with your command

First the exclusion condition. To exclude "*.EXE" say ! -name "*.EXE". The condition in the OP takes all files that contain a letter different from \,., E or X.

The other thing is that for this specific purpose it makes sense to check only executable files. This can be accomplished with the -executable predicate.

The rest of it seems ok.

Here is a complete version

 find -executable -type f ! -name "*.EXE"  -exec chmod a-x {} +
Dima Chubarov
  • 16,199
  • 6
  • 40
  • 76
0

I know it's been a long time, but I would just like to share my approach here.

I completely agree with @Dima Chubarov 's approach, however also the following can be done:

find . -type f ! -regex ".*\.EXE$" | xargs chmod a-x

Note that here we are negating the regex pattern (with ! before -regex) instead of trying "not to match" the pattern .EXE (using the regex [^\.EXE$], which actually does not do what you need, as @Dima said

The condition in the OP takes all files that contain a letter different from \,., E or X.

)

Regarding the xargs command, at least for me, is more intuitive than using the -exec flag, and it works perfectly fine when coupled to find command.

-1

if find . -name "*.EXE" -exec chmod a-x {} + doesn't work, then I'd just "find . -name .. -print" into a script and edit the script.

paulsm4
  • 114,292
  • 17
  • 138
  • 190