tags:

views:

231

answers:

2

I would like to do something like:

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

Possible? Some other comparable method available?

+6  A: 

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 execs 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.

ephemient
Thanks ephemient. The kfmclinet/gnome-open is exactly what I needed.
Duck
+1 excellent; informative, quality and safe code. Though personally I'm not sure I'd use "$@" when only specifying a single positional argument. I'd use "$1" to explicitly indicate that or use + instead of \; if supported by `kpdf`.
lhunath
A: 

If your goal is just not having to close one pdf in order to see the next one as opposed to display each pdf in its own separate instance, you might try

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

With the plussed variant, -exec builds the command line like xargs would so all the files found would be handed to the same instance of kpdf. The & in the end then affects the whole find. With very large numbers of files found it might still open them in batches because command lines grow too long, but with respect to ressource consumption on your system this may even be a good thing. ;)

kpdf has to be able to take a list of files on the command line for this to work, as I don't use it myself I don't know this.

Olfan