Can the find command's "exec" feature start a program in the background?

bash, linux, unix

Solution

Firstly, it won't work as you've typed, because the shell will interpret it as

find . -iname "*Advanced*Linux*Program*" -exec kpdf {} &
\;

which is an invalid `find` run in the background, followed by a command that doesn't exist.

Even escaping it doesn't work, since `find -exec` actually `exec`s the argument list given, instead of giving it to a shell (which is what actually handles `&` for backgrounding).

Once you know that that's the problem, all you have to do is start a shell to give these commands to:

find . -iname "*Advanced*Linux*Program*" -exec sh -c '"$0" "$@" &' kpdf {} \;

On the other hand, given what you're trying to do, I would suggest one of

find ... -exec kfmclient exec {} \;  # KDE
find ... -exec gnome-open {} \;      # Gnome
find ... -exec xdg-open {} \;        # any modern desktop

which will open the file in the default program as associated by your desktop environment.

Problem

I would like to do something like: ``` find . -iname "*Advanced*Linux*Program*" -exec kpdf {} & \; ``` Possible? Some other comparable method available?

Original source