[COLUG] gawk question
Nathan C. Overley
NOverley at sm.k12.oh.us
Tue Aug 22 11:36:41 EDT 2006
Thanks everyone for all your help. I was able to get it to do what I needed.
Nathan
On 20 Aug 2006 at 8:23, William Yang wrote:
> Nathan Overley wrote:
> > Thanks for the suggestions. Is there a way to dynamically assign the STUDENT
> > variable with the names of the users directories?
>
> STUDENTS="User1 User2 ... UserN"
>
> for i in ${STUDENTS}; do
> STUDENTDIR=`getpwent | gawk -v user="${i}" -F: \
> '( $1 == user ) { print $6 }'`
> CWD=`pwd`
> cd $STUDENTDIR
> find . -maxdepth 1 -type -d \! -name career | xargs echo rm -rf
> cd $CWD
> done
>
> # always be very careful with automated find/remove combinations.
> # use this code at your own risk.
>
>
> > Thanks,
> > Nathan
> >
> >> ===== Original Message From jmglov at wmalumni.com, Central OH Linux User Group
> > <colug432 at colug.net> =====
> >> 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
> >> _______________________________________________
> >> colug432 mailing list colug432 at colug.net
> >> http://www.colug.net/mailman/listinfo/colug432
> >
> >
> >
> > _______________________________________________
> > colug432 mailing list colug432 at colug.net
> > http://www.colug.net/mailman/listinfo/colug432
> >
>
>
> --
> William Yang
> wyang at gcfn.net
> _______________________________________________
> colug432 mailing list colug432 at colug.net
> http://www.colug.net/mailman/listinfo/colug432
>
More information about the colug432
mailing list