I want to incorporate something like:
for f in */*; do mv "$f" "${f%/*}/foo.${f##*.}"; done
Into my find x -exec y {} \;-style workflow.
The for loop construct & "$f" variable will likely be omitted; the loop will be substituted by standard -exec iterating behaviour, and the variable (containing the filename of the current iteration), by {}.
But it seems like these two different syntaxes are incompatible/problematic. Especially because of the conflicting braces and semicolons, etc.
{}needs to be the whole argument in order to be expanded. You cannot append or prepend text to that argument. See your tip #3 – schily Oct 20 '18 at 20:43gnu find 4.6.0works perfectly with synthax provided in tip 3. For example ths works fine :find . -maxdepth 1 -exec echo '{}' '{}'.txt \;. Maybe you are using a non gnu find. – George Vasiliou Oct 20 '18 at 22:27find . -maxdepth 1 -exec echo newtexthere'{}'.txt \;– George Vasiliou Oct 20 '18 at 22:31-exec prog1 {} ';' -exec prog2 {} ';', thenprog2will be executed only ifprog1exits with status 0. (1b) I don’t understand why you’re even mentioning-exec echo {} \; -exec cat {} \;, as I don’t see how you’re using it to solve this problem (renaming). (1c)-exec echo {} \;is equivalent to-print. (2a) To search the current directory and all sub-directories under it, recursively, it’s best to say simplyfind .. … (Cont’d) – G-Man Says 'Reinstate Monica' Jun 18 '20 at 05:05find ./*orfind */*), you’re forcing the shell to expand that glob. Likels *, this is redundant when you’re invoking a program that already knows how to enumerate directories. (2b) Unless you have setdotglob,find ./*(andfind */*) will overlook top-level files and directories whose names begin with.. (2c) Whenever you use a glob, you run the risk of generating a command line that’s longer than the maximum. … (Cont’d) – G-Man Says 'Reinstate Monica' Jun 18 '20 at 05:05ARG_MAXis commonly 10000 or more, sometimes as high as 100000 or 1000000, so commands likecat *are probably safe from this pitfall. But when you’re invoking a program that already knows how to enumerate directories (e.g.,find,ls,chmod,cp,grep,rm, …), why take the risk? (Note that some of us can remember whenARG_MAXwas 512.) – G-Man Says 'Reinstate Monica' Jun 18 '20 at 05:05