[oclug] find help

Jacques B. jjrboucher at gmail.com
Sun Jan 20 18:09:21 EST 2008


On Jan 20, 2008 2:50 PM, Woogie <woogie at gmail.com> wrote:
> I shudder to think why you're making a script to do this, but I'll
> work on the premise the reason isn't malicious.
>
> Try rearranging your quotes so that the argument to echo is properly
> escaped instead of the whole command, and give echo a null character
> (pair of single quotes), like so:
> find . -name \* -type f -exec echo '' > "{}" \;
>
>
> Note, that I have not tested this. If that doesn't work, there is
> another alternative:
>
> find . -name \* -type f -exec rm "{}" && touch "{}" \;
>
> I haven't tested that either. Also, that one might not work for you
> because any special permissions or ownerships will get replaced. Also,
> I think the "&&" might not function correctly inside that -exec block
> either.
>
>
> On Jan 20, 2008 2:23 PM, James Lockie <bjlockie at lockie.ca> wrote:
> > I want to make all files 0 bytes.
> > I tried this:
> > find . -name \* -type f -exec "echo > {}" \;
> >
> > This shows the correct file listing:
> > find . -name \* -type f -exec "ls -l {}" \;
> >
> > --

Instead of using the && (if that does not work), can't you just have
another -exec command (I believe you can have several).  The first
-exec for the rm, the second -exec for the touch.

But I agree, I hope this is not for malicious reasons.  One might need
to do this if an application required that certain data file names
already exists in order to work and you wanted to clear all the data
and recreate the required blank files.

Jacques B.


More information about the OCLUG mailing list