Find Cut – ‘No Such File or Directory’ Error with ‘-exec’ in Find Command

cutfind

I have a bunch of folders which have a subfolder somewhere called 360.

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

output:

find: echo "./workspace/6875538616c6/raw/2850cd9cf25b/360": No such file or directory

For each found item, I want to do a curl call, and trigger a Jenkins build job.
My problem is that ./ part at the start. I should be able to cut it off like this:

find . -name '360' -type d -exec 'echo {} | cut -c 2-' \;

But because it starts with a ./ it will just be executed ("No such file or directory").
How can I get the output from find, without the leading ./?

update:

Here is the whole thing with a jenkins curl call:

find reallylongfolderstructure -name '360' -type d -exec 'curl http://user:token@ourdomain.net/jenkins/job/jobname/buildWithParameters?token=ourtoken&parameter={}' \; 

output

08:53:52 find: ‘curl http://user:token@ourdomain/jenkins/job/jobname/buildWithParameters?token=ourtoken&parameter=reallylongfolderstructure/something/lol/360’: No such file or directory

Best Answer

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:token@ourdomain.net/jenkins/job/jobname/buildWithParameters?token=ourtoken&parameter={}' \; 
Related Question