[COLUG] gawk question

Josh Glover jmglov at gmail.com
Sat Aug 19 01:11:50 EDT 2006


On 19/08/06, Steven Huwig <shuwig at columbus.rr.com> wrote:

>    $ find -d . -mindepth 2 \! -name career -exec rm -d -i {} \;
>
> The -i flag at the end will prompt you for every file deletion, since
> I didn't test that command line thoroughly.

Good suggestion. With dangerous commands, I usually do this first:

STUDENTS="User1 User2 ... UserN"
cd /home
for i in ${STUDENTS}; do
 find $i/ -maxdepth 1 -type -d \! -name career | xargs echo rm -rf
done

(Thanks for the "\! -name foo" trick--I did not know that bit of find
syntax). Then, I inspect the output, and if satisfied, remove the
"echo" (or, in most cases, replace it with "sudo"), as such:

STUDENTS="User1 User2 ... UserN"
cd /home
for i in ${STUDENTS}; do
 find $i/ -maxdepth 1 -type -d \! -name career | xargs sudo rm -rf
done

The key point to take away is to be *very* careful with destructive
commands, especially when executing them as root!

-Josh


More information about the colug432 mailing list