Posted on 01-14-2019 09:13 AM
rm -rf /Users/user/Documents/
rm -rf /Users/user/Downloads/
rm -rf /Users/user/Desktop/
rm -rf /Users/user/Pictures/
rm -rf /Users/user/Music/*
exit 0
*Hi all,
First time posting here, so apologies if this has already been posted before. We are currently using the script above to delete unwanted files created by students in our institution. However, we'd like to exclude a sub-directory called 'Apple Music Apps' within directory /Users/user/Music which has a file called 'LoopsDatabaseV09.db' which we don't want to delete.
Any help is greatly appreciated
Thank you
Solved! Go to Solution.
Posted on 01-15-2019 06:21 AM
@sudhan Try this out.
First delete the files except the one you want to keep:
find /Users/user/Music ! -name "LoopsDatabaseV09.db" -type f -exec rm "{}" ;
Then delete the empty directories recursively:
find /Users/user/Music -type d -exec rmdir -p {} ;
This should leave LoopsDatabaseV09.db in the same directory it was originally located.
Posted on 01-14-2019 11:22 AM
@sudhan Completely untested, but something like rm -rf /Users/user/Music/* !('LoopsDatabaseV09.db')
should work.
Posted on 01-15-2019 01:31 AM
Hi @dan-snelson
Thank you for your instant reply. I tried your script and unfortunately, it's not working for us.
Please see the attached image.
Thank you once again.
Posted on 01-15-2019 05:17 AM
I would set the system immutable flag for LoopsDatabaseV09.db with "sudo chflags simmutable $pathToFile". With that set even a "sudo rm -rf $pathToFile" will fail, and the file and its parent directories will survive. The downside is that the rm will create an error message.
A "sudo chflags nosimmutable $pathToFile" is needed to make the file 'removable' again.
Posted on 01-15-2019 06:21 AM
@sudhan Try this out.
First delete the files except the one you want to keep:
find /Users/user/Music ! -name "LoopsDatabaseV09.db" -type f -exec rm "{}" ;
Then delete the empty directories recursively:
find /Users/user/Music -type d -exec rmdir -p {} ;
This should leave LoopsDatabaseV09.db in the same directory it was originally located.
01-11-2022 04:31 PM - edited 01-11-2022 04:33 PM
Giving error.
find /Users ! -name "administrator" -type d -exec rm "{}" ;
find: -exec: no terminating ";" or "+"
Posted on 08-10-2022 05:59 PM
Mine is also giving error:
1:233: execution error: find: -exec: no terminating ";" or "+" find: -exec: no terminating ";" or "+" (1)
Here is my script
#!/bin/bash
lastUser=`defaults read /Library/Preferences/com.apple.loginwindow lastUserName`
find /Users/$lastUser/Desktop ! -name "1.jpg" -type f -exec rm "{}" ;
find /Users/$lastUser/Desktop -type d -exec rmdir -p {} ;
Posted on 01-15-2019 06:57 AM
Hi @mschroder ,
Thank you for getting back. I apologies, but what you are suggesting it bit beyond my basic knowledge of JAMF. But thank you anyway for your suggestion.
Posted on 01-15-2019 07:05 AM
Hi @ryan.ball ,
IT WORKED!!!!!!!!! Thank you also for getting back. Really appreciate your help. Hope this is also helpful for anyone else who's having the same issue.
Best wishes,
Sudhan
Posted on 08-07-2021 04:26 PM
Why are you trying to do this? The Loops should be a shared resource available to all users. It seems like you have multiple accounts that might be downloading multiple loops into personal accounts. The better move would be to move all loops into the shared loops directory.