unix - Bash, find and delete whilst retaining directory -


i trying hand @ bash scripting , appreciated.

the script supposed find users users in /users/ , delete inside. movies, documents, desktop , music.

whilst still retaining directory emptying it. excluding user files of ladmin, shared , guest.

when execute. doesn't empty files though feed expect. missing simple here?

dir_cd=/users/  cd $dir_cd  find . -type d ! -name "*ladmin*" ! -name "*guest*" ! -name "*shared*" \        -maxdepth 1 -print -exec rm -rf {}/desktop/* \; find . -type d ! -name "*ladmin*" ! -name "*guest*" ! -name "*shared*" \        -maxdepth 1 -print -exec rm -rf {}/documents/* \; find . -type d ! -name "*ladmin*" ! -name "*guest*" ! -name "*shared*" \        -maxdepth 1 -print -exec rm -rf {}/movies/* \; find . -type d ! -name "*ladmin*" ! -name "*guest*" ! -name "*shared*" \        -maxdepth 1 -print -exec rm -rf {}/music/* \; 

like this?

for d in /users/*;     case ${d#*/} in ladmin | guest | shared ) continue ;; esac     rm -rf "$d"/desktop/* "$d"/documents/* "$d"/movies/* "$d"/music/* done 

with bash extended globbing single wildcard expression.


Comments

Popular posts from this blog

c++ - CryptStringToBinary API behavior -

java.util.scanner - How to read and add only numbers to array from a text file -

iphone - Three second countdown in cocos2d -