[WBEL-users] File deletion

Luke Scharf lscharf@aoe.vt.edu
Wed Jan 19 23:45:34 CST 2005


On Wed, 2005-01-19 at 17:42, Francies Moore wrote:
> What I need to do is to remove the files but leave the directories intact.
> 
> Is it possible to use a script to do this?  If so, how?  I realise rm 
> -rf removes subdirectories as well as files!

The following command should take care of it:
	find /some/path -type -f -exec rm -i {} \;

It will run an individual "rm -i $FILENAME" for each file it finds.  You
can change the '-i' to a '-fv' or even '-f' if you're brave, but since
I'm making these instructions for someone else, I'd rather have them
press "y" 500 times then loose the wrong files!  :-)

The reason I would do it with find -exec, instead of with backticks ("rm
-i `find /some/path -type f`") is because the shell only has so much
space for arguments to a particular command.  When you try to delete
thousands of files this way, it gives up.  I'm not sure if "|xargs"
suffers from this problem or not.

I hope this helps!
-Luke

-- 
Luke Scharf, Systems Administrator
Virginia Tech Aerospace and Ocean Engineering




More information about the Whitebox-users mailing list