Can the find "exec" command run the program in the background?

I would like to do something like:

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

Possible? Is any other comparable method available?

+1
source share
2 answers

Firstly, it will not work as you typed, because the shell will interpret it as

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

which is invalid find is executed in the background, followed by a command that does not exist.

Even escaping does not work, since find -exec is actually exec given a list of arguments, instead of giving it to the shell (this is what & is actually processing for the wallpaper).

Once you know that , that the problem is, all you have to do is launch the shell to give the following commands:

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

On the other hand, given what you are 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 program by default, corresponding to your desktop environment.

+12
source

If your goal is simply not to close one pdf file to see the next, rather than showing each PDF file in a separate copy, you can try

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

With the plus option, -exec creates a command line such as xargs, so all found files will be transferred to a single kpdf instance. Then and at the end it affects the whole find. With a very large number of files found, it can still open them in packages, because the command lines are too long, but with regard to resource consumption in your system, this can be even good .;)

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

+1
source

Source: https://habr.com/ru/post/958641/


All Articles