Find -exec not working in fish

findfish

While using fish as my shell, i'm trying to set permissions on a bunch of c source files in current dir with

find . -type f -name "*.c" -exec chmod 644 {} +;

I get an error

find: missing argument to `-exec'

or

find . -type f -name "*.c" -exec chmod 644 {} \;

I get an error

chmod: cannot access '': No such file or directory

What's wrong?

Best Answer

fish happens to be one of the few shells where that {} needs to be quoted.

So, with that shell, you need:

find . -type f -name '*.c' -exec chmod 644 '{}' +

When not quoted, {} expands to an empty argument, so the command becomes the same as:

find . -type f -name '*.c' -exec chmod 644 '' +

And find complains about the missing {} (or ; as + is only recognised as the -exec terminator when following {}).

With most other shells, you don't need the quotes around {}.

Related Question