From: srikanth on
On Apr 20, 7:15 pm, pk <p...(a)pk.invalid> wrote:
> srikanth wrote:
> > See I will tell you my problem...
> > I have a dir which contains lots of files. I want to search one file
> > and delete it. Then I need to create a file with same name.
> > So first I am trying to search for that file in my dir and removing.
> > This is the command I have tried and got success  "find Desktop/Test -
> > name test -exec rm -rf {} \;"
> > 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.
>
> Your "find" command is quite dangerous written that way. If there is a
> directory (anywhere) with the same name as the file you're looking for, it
> will be deleted.
>
> If you just want to remove and recreate that file, you can do
>
> find Desktop/Test -type f -name test -exec sh -c '> "$1"' sh {} \;
>
> that will truncate to 0 bytes /all/ files named "test" under the hierarchy
> rooted at Desktop/Test. If you are looking for a specific file called "test"
> (among many), you need to add more checks like for example grepping for the
> content or others.
>
> Again, that's surely not your outer problem, but good luck.

Can you please explain what does it mean sh -c '> "$1"' sh {} \;
From: Bill Marcum on
On 2010-04-20, srikanth <srikanth007m(a)gmail.com> wrote:
>
> See I will tell you my problem...
> I have a dir which contains lots of files. I want to search one file
> and delete it. Then I need to create a file with same name.
> So first I am trying to search for that file in my dir and removing.
> This is the command I have tried and got success "find Desktop/Test -
> name test -exec rm -rf {} \;"
> 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.

You are deleting a file named Desktop/Test/test and then trying to create
a file named Desktop/Test/test/test.

--
The culpability of a female or oneself is a matter of opinion, however.
-- ¬R
From: srikanth on
On Apr 20, 7:22 pm, Bill Marcum <marcumb...(a)bellsouth.net> wrote:
> On 2010-04-20, srikanth <srikanth0...(a)gmail.com> wrote:
>
>
>
> > See I will tell you my problem...
> > I have a dir which contains lots of files. I want to search one file
> > and delete it. Then I need to create a file with same name.
> > So first I am trying to search for that file in my dir and removing.
> > This is the command I have tried and got success  "find Desktop/Test -
> > name test -exec rm -rf {} \;"
> > 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.
>
> You are deleting a file named Desktop/Test/test and then trying to create
> a file named Desktop/Test/test/test.
>
> --
> The culpability of a female or oneself is a matter of opinion, however.
> -- ¬R

Yes exactly.
From: pk on
srikanth wrote:

>> You are deleting a file named Desktop/Test/test and then trying to create
>> a file named Desktop/Test/test/test.
>>
>
> Yes exactly.

Exactly wrong. If you really want that, you need to create the directory
first; if you don't want that, you are using the wrong command.
From: pk on
srikanth wrote:

> Can you please explain what does it mean sh -c '> "$1"' sh {} \;

Can you please read what I wrote and the manual of your shell? Here's what I
wrote:

"that will truncate to 0 bytes /all/ files named "test" under the hierarchy
rooted at Desktop/Test."

"truncate to 0 bytes" means that the file will become empty, 0 bytes long.