From: srikanth on
On Apr 20, 5:11 pm, pk <p...(a)pk.invalid> wrote:
> 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.
Ok here it is what I am using

find Desktop/Programs -name test.sh -exec sh -c 'rm -rf "$1";touch
"$1"/test' sh {} \;
touch: cannot touch `Desktop/Programs/test.sh/test': No such file or
directory

File is getting removed but touch was showing error as above. I have
tried with the command what I was provided in my first mail with lots
of modification but no luck with touch,
From: srikanth on
On Apr 20, 5:25 pm, srikanth <srikanth0...(a)gmail.com> wrote:
> On Apr 20, 5:11 pm, pk <p...(a)pk.invalid> wrote:
>
> > 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.
>
> Ok here it is what I am using
>
> find Desktop/Programs -name test.sh -exec sh -c 'rm -rf "$1";touch
> "$1"/test' sh {} \;
> touch: cannot touch `Desktop/Programs/test.sh/test': No such file or
> directory
>
> File is getting removed but touch was showing error as above. I have
> tried with the command what I was provided in my first mail with lots
> of modification but no luck with touch,

find Desktop/Programs -name test.sh -exec sh -c 'rm -rf "$1";touch
"$1"/test.sh' sh {} \;
The above command ran successfully with out any errors but file was
not created.
From: pk on
srikanth wrote:

>> Ok here it is what I am using
>>
>> find Desktop/Programs -name test.sh -exec sh -c 'rm -rf "$1";touch
>> "$1"/test' sh {} \;
>> touch: cannot touch `Desktop/Programs/test.sh/test': No such file or
>> directory
>>
>> File is getting removed but touch was showing error as above. I have
>> tried with the command what I was provided in my first mail with lots
>> of modification but no luck with touch,
>
> find Desktop/Programs -name test.sh -exec sh -c 'rm -rf "$1";touch
> "$1"/test.sh' sh {} \;
> The above command ran successfully with out any errors but file was
> not created.

You need to do at least

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

but much better is

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

From: srikanth on
On Apr 20, 5:53 pm, pk <p...(a)pk.invalid> wrote:
> srikanth wrote:
> >> Ok here it is what I am using
>
> >> find Desktop/Programs -name test.sh -exec sh -c 'rm -rf "$1";touch
> >> "$1"/test' sh {} \;
> >> touch: cannot touch `Desktop/Programs/test.sh/test': No such file or
> >> directory
>
> >> File is getting removed but touch was showing error as above. I have
> >> tried with the command what I was provided in my first mail with lots
> >> of modification but no luck with touch,
>
> > find Desktop/Programs -name test.sh -exec sh -c 'rm -rf "$1";touch
> > "$1"/test.sh' sh {} \;
> > The above command ran successfully with out any errors but file was
> > not created.
>
> You need to do at least
>
> -exec sh -c 'rm -rf "$1"; mkdir "$1"; touch "$1"/test.sh' sh {} \;
>
> but much better is
>
> sh -c 'rm -rf -- "$1" && mkdir -- "$1" && touch -- "$1"/test.sh' sh {} \;

I want to create a file under the same directory where I am doing
search. Is there an alternative way to create a file.
From: pk on
srikanth wrote:

>> > find Desktop/Programs -name test.sh -exec sh -c 'rm -rf "$1";touch
>> > "$1"/test.sh' sh {} \;
>> > The above command ran successfully with out any errors but file was
>> > not created.
>>
>> You need to do at least
>>
>> -exec sh -c 'rm -rf "$1"; mkdir "$1"; touch "$1"/test.sh' sh {} \;
>>
>> but much better is
>>
>> sh -c 'rm -rf -- "$1" && mkdir -- "$1" && touch -- "$1"/test.sh' sh {} \;
>
> I want to create a file under the same directory where I am doing
> search.

The above does (also) that. Did you try it?
If you simply want to create a file, just do touch "$1"/yourfile. Why are
you removing the directory?

> Is there an alternative way to create a file.

You should explain what is your real problem. The big picture.