From: srikanth on
Hi all,
I have a problem while executing multiple command with in a Find
command. Actually my requirement is to find a file in a specific
directory and remove it and want to create a file with the same name
which
I have searched for. Here is what I am doing

find Desktop/Test -name test -exec rm -rf {} \; -exec touch {}/test \;

From the above command first command is executing successfully. But
when comes to touch command it was not creating file. Is there any
thing wrong under touch syntax or expressions? Can any one please
help me. Also please suggest me if
there are any easy way to do it.
From: pk on
srikanth wrote:

> Hi all,
> I have a problem while executing multiple command with in a Find
> command. Actually my requirement is to find a file in a specific
> directory and remove it and want to create a file with the same name
> which
> I have searched for. Here is what I am doing
>
> find Desktop/Test -name test -exec rm -rf {} \; -exec touch {}/test \;
>
> From the above command first command is executing successfully. But
> when comes to touch command it was not creating file. Is there any
> thing wrong under touch syntax or expressions? Can any one please
> help me. Also please suggest me if
> there are any easy way to do it.

use

-exec sh -c 'all the commands you want with "$1"' sh {} \;

From: srikanth on
On Apr 20, 4:51 pm, pk <p...(a)pk.invalid> wrote:
> srikanth wrote:
> > Hi all,
> > I have a problem while executing multiple command with in a Find
> > command. Actually my requirement is to find a file in a specific
> > directory and remove it and want to create a file with the same name
> > which
> > I have searched for. Here is what I am doing
>
> > find Desktop/Test -name test -exec rm -rf {} \; -exec touch {}/test \;
>
> > From the above command first command is executing successfully. But
> > when comes to touch command it was not creating file. Is there any
> > thing wrong under touch syntax or expressions?  Can any one please
> > help me. Also please suggest me if
> > there are any easy way to do it.
>
> use
>
> -exec sh -c 'all the commands you want with "$1"' sh {} \;

I have tried with that alternative as well. But no luck.
second command is not executing, i.e touch. Is there any problem with
the syntax or the way i am using?
From: pk on
srikanth wrote:

> On Apr 20, 4:51 pm, pk <p...(a)pk.invalid> wrote:
>> srikanth wrote:
>> > Hi all,
>> > I have a problem while executing multiple command with in a Find
>> > command. Actually my requirement is to find a file in a specific
>> > directory and remove it and want to create a file with the same name
>> > which
>> > I have searched for. Here is what I am doing
>>
>> > find Desktop/Test -name test -exec rm -rf {} \; -exec touch {}/test \;
>>
>> > From the above command first command is executing successfully. But
>> > when comes to touch command it was not creating file. Is there any
>> > thing wrong under touch syntax or expressions? Can any one please
>> > help me. Also please suggest me if
>> > there are any easy way to do it.
>>
>> use
>>
>> -exec sh -c 'all the commands you want with "$1"' sh {} \;
>
> I have tried with that alternative as well. But no luck.
> second command is not executing, i.e touch. Is there any problem with
> the syntax or the way i am using?

It-s difficult to tell it you don't provide the exact command you used. If
(guessing) that was something like

find ... -exec sh -c 'rm -rf "$1";touch "$1"/test' sh {} \;

obviously it's no wonder that it didn't work as you have to create the
directory first. Otherwise, post the /exact/ command you used.


From: Ben Bacarisse on
srikanth <srikanth007m(a)gmail.com> writes:

> On Apr 20, 4:51 pm, pk <p...(a)pk.invalid> wrote:
>> srikanth wrote:
<snip>
>> > Here is what I am doing
>>
>> > find Desktop/Test -name test -exec rm -rf {} \; -exec touch {}/test \;
>>
>> > From the above command first command is executing successfully. But
>> > when comes to touch command it was not creating file. Is there any
>> > thing wrong under touch syntax or expressions?  Can any one please
>> > help me. Also please suggest me if
>> > there are any easy way to do it.
>>
>> use
>>
>> -exec sh -c 'all the commands you want with "$1"' sh {} \;
>
> I have tried with that alternative as well. But no luck.
> second command is not executing, i.e touch. Is there any problem with
> the syntax or the way i am using?

How could anyone possibly know? :-) Please, at least post the command
you used!

--
Ben.