I tried this bash command:
find /var/www/ -path '*wp-admin/index.php' -exec mv {} $(dirname {})/index_disabled
But the second {}
is not executed.
It results in just ./index_disabled
instead.
How can I use the found parameter twice in the execute command?
Your problem is not that it's not interpreted twice, as doing
will show. The problem is that
{}
can't be used as an argument to a function, as you're trying to. In my (limited) experience, if you want to get clever withfind
and the contents of{}
, you'll need to write a shell script that is invoked fromfind
, that takes{}
as its one and only argument, and that does the clever things inside that script.Here's an example clever script:
Here's me using it with find, and the last few lines of the results:
As you can see, if I replaced
echo
in the shellscript withmv
, I'd get the desired result.You'll have to use the
xargs
command and a little trick:You could use a simple for loop to solve this.