0

For example

find -name "*.jpg" -exec myprogram {} 

Is it from the argument list in main()?

Biffen
  • 6,249
  • 6
  • 28
  • 36
AdmiralSmith
  • 105
  • 2
  • 5
    No, in this command `{}` is replaced by result of each match of the `find`. So that your program is invoked as `myprogram foobar.jpg`. – Jean-Baptiste Yunès Oct 09 '16 at 18:50
  • 2
    You are missing `\;`. Your command should be `find -name "*.jpg" -exec myprogram {} \;` – Luc M Oct 09 '16 at 18:54
  • 1
    A better approach should be to build the command line using `{} +`. Having said that, your question is exceedingly terse. What are you trying to accomplish? – sjsam Oct 09 '16 at 19:35

1 Answers1

3

If you wish to pass all the jpg file names as one argument list to your program, you can use xargs

find . -name "*.jpg" | xargs myprogram 

Refer to Arguments to main in C on how to access these arguments passed to myprogram.

Your version will invoke your program multiple times for each jpg file it finds

find . -name "*.jpg" -exec myprogram '{}' \; 

You could achieve the same results as xargs if you terminate your find -exec with +

find . -name "*.jpg" -exec myprogram '{}' +

Reference: https://en.wikipedia.org/wiki/Xargs

Community
  • 1
  • 1
N Kumar
  • 31
  • 3
  • 1
    `find … -print0 | xargs -0 …` if you want it to work with ‘unusual’ filenames. – Biffen Oct 09 '16 at 19:17
  • Nice. The `{} +` is used to build the command line.. But, to be fault proof you might need to use `-print0` with the `find` to make each filename null terminated. – sjsam Oct 09 '16 at 19:28
  • 1
    {} + is safe, no need for -print0. -print0 is only needed for | xargs – Bodo Thiesen Oct 09 '16 at 19:48