Re: OT: Shell scripting wizardry needed


Subject: Re: OT: Shell scripting wizardry needed
From: Gawain (lists0501@guitar.net)
Date: Thu Dec 20 2001 - 13:52:21 MST


At 2:00 PM -0500 on 12/20/01, nathan r. hruby wrote:

>To whit, if someone had a symbolic link to / in /foo/bar, you'd probably
>end up deleting your entire filesystem with the find command you list
>above. I'd suggest adding the -mount (stay on current filesystem) option
>and adding a -type flag to ignore symbolic links, or to be further
>pedantic, specfiy "-type fd" to find files and directories only.
>
>A super secure peson would write two find commands, one for files the
>simply rm's the old crufty files, and one that runs right after that
>rmdir's old crufty directories. Thus getting rid on any kind of
>nastytitude that could be casued by running "rm -rf" as root.

Thanks for the sound advice, Nathan. I've modified the script to read:

find /foo/bar -type d -mount -mtime +20 -maxdepth 1 -exec rm -rf '{}' ';'

Using the -type fd directive generated a 'find: invalid argument 'fd'
to '-type'' error, but it appears that the -type d flag gets files
too, so I used that.

I was going to try the two stage approach but the file deletion step
changes the modified time of the directories so the second command
doesn't catch them. Is there a good way around this?

Gawain



This archive was generated by hypermail 2a24 : Thu Dec 20 2001 - 14:05:49 MST