"No such file or directory" when using "-exec" with find

You write

because it starts with a ./ it will just be executed ("No such file or directory").

This isn't what's happening. You have provided a single command to the find ... -exec parameter of echo "{}". Note that this is not echo and the directory found by find; it's a single command that includes a space in its name. The find command (quite reasonably) cannot execute a command called echo "./workspace/6875538616c6/raw/2850cd9cf25b/360".

Remove the single quotes around the -exec parameter and you may find you don't need any additional changes or workarounds:

find . -name '360' -type d -exec echo "{}" \;

Similarly here you need to remove the quoting of the entire value passed to -exec. But in this case you still need to quote the storage arguments so the shell cannot interpret &, etc.

find reallylongfolderstructure -name '360' -type d -exec curl 'http://user:[email protected]/jenkins/job/jobname/buildWithParameters?token=ourtoken&parameter={}' \; 

The issue is you are quoting both the utility name and the argument as a single string, which causes find to try to execute the whole thing as the name of the command.

Instead use

find . -type d -name '360' -exec curl "http://user:[email protected]/jenkins/job/jobname/buildWithParameters?token=ourtoken&parameter={}" ';' 

In some older implementations of find, {} won't be recognized as the pathname that find has found when it's concatenated with another string as above, and you would have to use a child shell instead:

With your call to curl:

find -type d -name '360' -exec sh -c '
    for pathname do
        curl "http://user:[email protected]/jenkins/job/jobname/buildWithParameters?token=ourtoken&parameter=$pathname"
    done' sh {} +

See also:

  • Understanding the -exec option of `find`

In bash:

shopt -s globstar

for pathname in ./**/360/; do
    curl "http://user:[email protected]/jenkins/job/jobname/buildWithParameters?token=ourtoken&parameter=$pathname"
done

The globstar shell option makes the ** glob pattern available. It works like *, but matches across slashes in pathnames.

Tags:

Find

Cut