Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

On a Mac, how can I create a script to automatically remove all user profile folders except a specific one on a reboot?

share|improve this question
    
Hi Donna. Have you tried anything yet? Just to get the full picture: Why would you need something like this? Do the users still exist and are you planning to force-delete their profile folders? –  slhck Feb 14 '13 at 20:03
    
This is for Macs in our university computer labs. We don't want student profiles to stay on the Macs. We use to add a few lines at the end of the periodic file in /usr/sbin to delete all folders in the User directory, but that also deleted our administrator account and the Shared folder. I want to delete all profiles except our admin account (support) and the Shared folder upon reboot. –  Donna Feb 14 '13 at 20:22
    
This is what was added to the end of the periodic file: –  Donna Feb 14 '13 at 20:25
    
rm -r -f /users/* mkdir /users/Shared chmod 777 /users/Shared –  Donna Feb 14 '13 at 20:25

1 Answer 1

If you know how your administrator account is called, you can use Bash's extglob features to remove everything but that user profile. Here, we'll assume that the admin account is called support:

#!/bin/bash
shopt -s extglob
rm -rf /Users/!(support|Shared)

The ! inverts the matches.

To have a script run on logout you can use a LogoutHook (but this is considered deprecated), or set up a launchd job that runs when OS X starts.

share|improve this answer
    
Thanks, I will try that tomorrow. –  Donna Feb 14 '13 at 23:24

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.