[oclug] Re: find
bjlockie at lockie.ca
Fri Apr 23 00:56:14 EDT 2004
On 04/22/04 21:05 Ian! D. Allen spoke:
> On Thu, Apr 22, 2004 at 06:10:18PM -0400, Bob Lockie wrote:
>>I need the file names but not the content.
> Many of the sample scripts people have been posting do not handle file
> names with blanks or GLOB characters in them, or directories containing
> things other than files. The scripts also don't handle hidden names.
> Most solutions put a newline into every file instead of emptying the file.
> Here's a Bourne shell answer, simliar to the best one posted so far and
> with the same limitations, that presumes you want empty files instead
> of files with newlines in them:
> for f in * ; do
> (Bourne shells don't require command names to do redirection.) The above
> is quite quick, since it's the Bourne shell emptying each file; no
> additional process needs to be created. The loop makes assumptions:
> hidden pathnames are missed, as are pathnames in sub-directories, and
> every pathname matched by "*" must be a file (not a directory); but, it
> does work fine on names containing blanks or other special characters.
> If you want a real solution that handles pathnames with arbitrary
> characters in their names (including blanks, TABs, newlines, and GLOB
> characters), handles hidden files (leading period), and works only on the
> files (not on symlinks, directories, pipes, special files, etc.) under
> the current directory, you use something like this:
> find . -type f -print0 | xargs -0 -n1 cp /dev/null
> The above descends into all directories. If you don't want the descent,
> add "-maxdepth 1" to the "find". The above pipeline is slow, since
> it executes one "cp" command for every file found; but, it makes no
> assumptions about names, finds even hidden names, and has no limitations.
> Add a "-name" clause to "find" to alter what files are emptied.
> Beware of scripts (and script writers) that make many assumptions.
> They will bite you some day. With Unix/Mac/Windows inter-operating,
> file names do have many strange (to Unix) characters in them.
I am using the Mozilla browser and I am a member of many mailing lists
that I have filters for.
I used to keep all the mail but I can't keep up with all the lists so
the files got rather large and I wanted to blank them out.
I needed to keep the files so they show up as folders in Mozilla.
Zeroing out the files found a floating point bug in Mozilla apparently. :-)
More information about the OCLUG