From: Jon LaBadie on
srikanth wrote:
....
> Then I am trying to create a file with same name. So I have tried find
> command to do both like
> find Desktop/Test -name test -exec rm -rf {} \; -exec touch {}/test \;

>
> The thing is it was deleting the file from the specified dir but not
> creating the file. I have told the same in the above as well. If it's
> not clear please let me know so that I will try to give much more info.

Assuming there is a file "Desktop/Test/test", the symbol {} is replaced
with "Desktop/Test/test". Thus {}/test is "Desktop/Test/test/test".
Not what you want and it causes touch to fail as "Desktop/Test/test"
does not exist.

Change your last -exec to simply "touch {}"
From: srikanth on
On Apr 20, 7:46 pm, Jon LaBadie <jlaba...(a)aXcXm.org> wrote:
> srikanth wrote:
>
> ...
>
> > Then I am trying to create a file with same name. So I have tried find
> > command to do both like
> > find Desktop/Test -name test -exec rm -rf {} \; -exec touch {}/test \;
>
> > The thing is it was deleting the file from the specified dir but not
> > creating the file. I have told the same in the above as well. If it's
> > not clear please let me know so that I will try to give much more info.
>
> Assuming there is a file "Desktop/Test/test", the symbol {} is replaced
> with "Desktop/Test/test".  Thus {}/test is "Desktop/Test/test/test".
> Not what you want and it causes touch to fail as "Desktop/Test/test"
> does not exist.
>
> Change your last -exec to simply "touch {}"
Jon, it worked perfectly what i want. But I have replied with bad
memory with out understanding what's going on.
Thanks a lot for you guys.

From: Robert Latest on
srikanth wrote:
>
> find Desktop/Test -name test -exec rm -rf {} \; -exec touch {}/test \;

For cases like this I like to build the command(s) with find's -printf
directive and pipe the result into a shell. Has the advantage that you
can leave off the pipe for a trial run.

find Desktop/Test -name test -printf 'rm -rf %p ; touch %p ' | sh

robert