Removing Specific User Folders

Jango Fett

Registered
Greetings,

The following script does not perform as expected

cd /Users/

for i in `ls | grep -v 'Jack' | grep -v 'Shared'´

do

echo 'password'| sudo -S rm -r -f $i

done


The objective is to remove all user folders except Jacks (the administrator account) and Shared.


If I execute

cd /Users/

ls | grep -v 'Jack' | grep -v 'Shared'

It will only show me the user, but if I try to use this command along with for i in it will be "lock" on > lines and will ignore

do

echo 'password'| sudo -S rm -r -f $i

done"

Or anything else I try to insert (exit... etc)


I cannot use grep -v twice with for i in? If so, any alternatives?


My thanks,

Jango
 
Back
Top