Jump to content

Delete all sub folder except two - syntax


Recommended Posts

Posted

Hi all,

 

I need a script to look in to a folder and delete all it's contents apart from two folders. I am using the following

shopt -s extglob
cd /Users
rm -rf !(administrator)

 

...which removes everything apart from a folder called "administrator", however I want it to delete everything apart from "administrator" and "Shared" how do I structure the syntax to define a second exclusion?

 

Thanks

  • 2 weeks later...
Posted

In case anyone digs this up, another user said that the syntax should be

shopt -s extglob
cd /Users
rm -rf !(administrator|Shared)

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now



×
×
  • Create New...