[NTLUG:Discuss] How do I make all files in a directory of zerolength?

Fred James fredjame at concentric.net
Wed Jun 6 12:45:11 CDT 2001


The only warning here would be that you lose you inode number, if that
is important, as it is sometimes.

sysmail at glade.net wrote:
> 
> To truncate all the files in a directory, how about:
> 
> for furt in ./* ; do
> rm $furt
> touch $furt
> done
> 
> or, if you need to traverse directories,
> 
> for slimemold in `find . -type f` ; do
> rm $slimemold
> touch $slimemold
> done
> 
> Naturally, you don't have to 'touch $slimemold' - the variable can be
> anything you want, within reason. Just don't name the the variable
> 'yourself'.  Bad form to touch $yourself...
> 
> Be aware if you truncate open files (such as active log files), you
> won't get the results you want.  For log files, check out logrotate.
> 
> Regards,
> 
> Carl
> 
> --
>                           |
>  /\\                      | Carl Haddick
>  \ \\  \__/ \__/          | GladeNet Communications
>   \ \\ (oo) (oo)          | 200 South Red River
>    \_\\/~~\_/~~\_         | Mexia, Texas 76667
>   _.-~===========~-._     | (254) 562-6381
>  (___________________)    | http://www.glade.net/~carl
>        \_______/          |
> 
> On Wed, 6 Jun 2001, Lance Simmons wrote:
> 
> > I want to go into a directory and make all the files of zero
> > length. What's the easiest way to do this?
> >
> > Do I need to save the filenames, delete the files, and then
> > touch the saved filenames?
> >
> > Is there a more direct way to achieve the result I'm looking for?
> >
> >
> 
> _______________________________________________
> http://www.ntlug.org/mailman/listinfo/discuss

-- 
...small is beautiful...



More information about the Discuss mailing list