On Sun, Jan 22, 2012 at 01:00:46PM -0600, clift...@volcano.org wrote: > On 12.01.2012 15:52, Doug Barton wrote: > >>> chflags -R noschg /usr/obj/usr > >>> rm -rf /usr/obj/usr
> > It's much faster to do: > > /bin/rm -rf ${obj}/* 2> /dev/null || /bin/chflags -R 0 ${obj}/* && > > /bin/rm -rf ${obj}/* > If I could just add one thing here, for those who might be tempted > to immediately cut and paste that elegant command line: > Consider, how does that command evaluate if the shell variable "obj" > is not set, and you're running that literal string as root? > A: You will very systematically wipe your entire server, starting > at the root, and doing a second pass to get any protected files you > missed. > I'd recommend something safer like approximately this (untested): > if ["X${obj}" != "X" -a -d ${obj}]; then cd ${obj} && (rest of cmds); > fi > Sorry for the wasted bandwidth, for those to whom it was obvious, > but anybody who has ever had to clean up after a junior admin's > attempt to do something a little too clever will appreciate why I'm > posting this. An easier way is to replace the first ${obj} with ${obj:?}, causing an error if obj is unset or null. One limitation is that it does not work with (t)csh. > On the efficiency front, for the core file deletion operators, I've > had good results with this trick (requires Perl and makes use of > its implicit-operand idioms): > find ${obj} | perl -nle unlink > If rm had an option to take files from standard input, or if > there's another program I'm not aware of which does this, it > could serve as the right-hand side of this. This does not handle all possible characters in filenames, such as a newline. The perlrun manpage suggests something with find's -print0 primary. Alternatively, use find's -unlink primary. -- Jilles Tjoelker _______________________________________________ freebsd-stable@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-stable To unsubscribe, send any mail to "freebsd-stable-unsubscr...@freebsd.org"