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:[email protected]/jenkins/job/jobname/buildWithParameters?token=ourtoken¶meter={}' \;
output
08:53:52 find: ‘curl http://user:token@ourdomain/jenkins/job/jobname/buildWithParameters?token=ourtoken¶meter=reallylongfolderstructure/something/lol/360’: No such file or directory
2 Answers 2
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¶meter={}' \;
-
I'm trying to do something similiar and it's not working.
find $WORKSPACE -name "*.mp4" -exec ffmpeg -i {} -qscale:v 1 -vf fps=6 {}_exportedFrame_%d.jpg \;
find: ffmpeg: No such file or directory Maybe you can help me out again :)Tamás– Tamás2019年01月17日 07:52:34 +00:00Commented Jan 17, 2019 at 7:52 -
@Tamás you probably don't have the
ffmpeg
program installed. Hence the error messageffmpeg: No such file or directory
.Chris Davies– Chris Davies2019年01月17日 09:20:11 +00:00Commented Jan 17, 2019 at 9:20 -
I do have it installed. I just get this error when I execute the shell command from a jenkins(mac build slave) build job. Executing the same command from the terminal works fine.Tamás– Tamás2019年01月17日 10:05:23 +00:00Commented Jan 17, 2019 at 10:05
-
@Tamás in that case I suggest you ask a fresh question. Reference this one - or my answer - if it helps provide context.Chris Davies– Chris Davies2019年01月17日 13:57:04 +00:00Commented Jan 17, 2019 at 13:57
-
All right. Added new question here: unix.stackexchange.com/questions/495076/…Tamás– Tamás2019年01月17日 14:43:19 +00:00Commented Jan 17, 2019 at 14:43
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¶meter={}" ';'
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¶meter=$pathname"
done' sh {} +
See also:
In bash
:
shopt -s globstar
for pathname in ./**/360/; do
curl "http://user:[email protected]/jenkins/job/jobname/buildWithParameters?token=ourtoken¶meter=$pathname"
done
The globstar
shell option makes the **
glob pattern available. It works like *
, but matches across slashes in pathnames.
-
Minor quibble: Some
find
releases, not some shells.Charles Duffy– Charles Duffy2018年07月06日 11:27:06 +00:00Commented Jul 6, 2018 at 11:27 -
@CharlesDuffy Well OK, I'll add that (as soon as I get to a computer). The csh shell will mess up if concatenating {} with a string, and that's the only current issue that I've seen anyone have recently. That's why I only mentioned shells.2018年07月06日 11:30:22 +00:00Commented Jul 6, 2018 at 11:30
-
@CharlesDuffy See e.g. unix.stackexchange.com/a/453198/1168582018年07月06日 12:17:52 +00:00Commented Jul 6, 2018 at 12:17
-
That's an issue in tcsh only without adequate quoting (AIUI, csh not my strength); with the quotes in your code it'd be fine. Re: the
find
end of things, quoting from the spec: If a utility_name or argument string contains the two characters "{}", but not just the two characters "{}", it is implementation-defined whether find replaces those two characters or uses the string without change.Charles Duffy– Charles Duffy2018年07月06日 15:13:31 +00:00Commented Jul 6, 2018 at 15:13 -
@CharlesDuffy You're right. With the quotes it'll be alright.2018年07月06日 18:27:44 +00:00Commented Jul 6, 2018 at 18:27
find
.