[K12OSN] OT Help with file deletion script

Peter Scheie peter at scheie.homedns.org
Thu Oct 25 16:31:37 UTC 2007


You may need || instead of just | on line 9.  And I usually put a 
semi-colon at the end of the 'if...' line, although that may not be 
mandatory.

Peter

Jim Kronebusch wrote:
> Okay, this removes everything but the .openwebmail directory.  It will still remove mail.
> 
> #!/bin/sh
> cd /home
> for userdir in `ls -C1`
> do
>   echo Working on $userdir...
>   cd /home/$userdir
>   for deleteme in `ls -C1 -a`
>   do
>    if [ $deleteme != mail ] | [$deleteme != .openwebmail ]
>     then
>       echo Removing $deleteme...
>       rm -ri $deleteme
>     else echo "Oops, encountered "$deleteme", not deleting!"
>     fi
>   done
> done
> 
> Not sure why mail still gets deleted, must be a small syntax error on line 9.
> 
> Here is a snip of results when ran:
> 
> Removing .ICEauthority...
> rm: remove regular file `.ICEauthority'? n
> Removing mail...
> rm: remove directory `mail'? n
> Removing .metacity...
> rm: descend into directory `.metacity'? n
> Removing .mozilla...
> rm: descend into directory `.mozilla'? n
> Removing Music...
> rm: remove directory `Music'? n
> Removing .nautilus...
> rm: descend into directory `.nautilus'? n
> Oops, encountered .openwebmail, not deleting!
> Removing Pictures...
> rm: remove directory `Pictures'? n
> 
> Jim
> 




More information about the K12OSN mailing list