0

I'm using below command to delete folder

rm -rf /Users/*/Library/Group\ Containers/UBF8T346G9.Office/User\ Content.localized/Templates.localized/

The command is working only for single user. I want to delete user template folder for all users. Templates folder automatically should be deleted for all user created on Mac.

  • Can you remove the folder for a second user with a modified command? If yes, please show two or more commands how you could do this for more than one user, one by one. – Bodo Feb 15 at 13:02
  • Do you not even get a "Permission denied" error? – Kusalananda Feb 15 at 13:20
1

The following illustrates one way to accomplish the goal with a script.

#!/bin/bash

# Get a list of users, filtering out service accounts, root, daemon, and nobody...
#
users=$(dscl . list /Users | grep -v -e '_' -e 'root' -e 'daemon' -e 'nobody')

# Loop through the list of users.
for user in "$users"; do
    # Put the path to the directory in a variable.
    # The quotes escape the spaces.
    #
    $dir="/Users/$user/Library/Group Containers/UBF8T346G9.Office/User Content.localized/Templates.localized/"

    # For each $user, delete the directory if it exists.
    if [ -d "$dir" ]; then
        rm -rf "$dir"
    fi
done

# These variables are no longer needed.
unset users
unset dir

Execute the following portion first to make sure that the list of users is expected and correct.

dscl . list /Users | grep -v -e '_' -e 'root' -e 'daemon' -e 'nobody'

After creating the script, it probably needs to be executed with sudo. If the script name is script.sh, then...

sudo script.sh
0

Please verify the Syntax!

It should go something like this:

for i in $(ls -1b /Users); do
 find "$i/Library/Group Containers/" -name Templates.localized --delete
done

Consider a testrun without '--delete' before first live usage.

  • 2
    Note two things: Don't parse the output of ls. Using /Users/*/Library/... should be working just fine. Your command would delete any directory (or file) called Templates.localized. Also, there is no --delete predicate in find (it's -delete). This will not solve the user's problem, which is likely permission related. – Kusalananda Feb 15 at 13:19

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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