Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

find command and inverse regex

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.

like image 499
DrBeco Avatar asked May 03 '12 18:05

DrBeco


People also ask

Can I use regex in Find command?

Different regex types are available for the command find: findutils. emacs (which is the default option unless otherwise specified) gnu-awk.

What does find command do in Linux?

The Linux find command is one of the most important and frequently used command command-line utility in Unix-like operating systems. The find command is used to search and locate the list of files and directories based on conditions you specify for files that match the arguments.


1 Answers

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 {} +
like image 146
Dmitri Chubarov Avatar answered Oct 09 '22 15:10

Dmitri Chubarov