Skip to main content

Hi all,



I'm trying to script this but can't get it to work for all users. What I'm trying is:



rm -rf /Users/*/Library/Application Support/Google/Chrome


But this isn't working even when run as root. If I run it as any logged in user it'll delete it from their own home directory, but I can't get it to run globally. I'm working with AD users if that makes a difference at all.



Am I missing something?

Yes,
The problem is the Asterix - which expands in this case to 'all users' - and then followed by a specific path..



So you are in fact (trying) to specify multiple paths - as a single path..
While a human could understand (the intent) of this - the poor computer cannot do so..



The command cannot be expanded..
Instead you would need to put this kind of delete command into a loop.
The loop would need to loop through each account
- specifying the exact path in each of those particular accounts, that you were trying to delete..
thus for each particular account, you are trying to:



rm -rf ${user account}/Library/Application Support/Google/Chrome



As this involves accounts other then your own it would need to run with root privileges, else it would fail.
So something like: ( PS: Below is an 'ls - ONE , NOT ls - L )



<code>



!/bin/bash



AccountList=$(ls -1 /Users)



for account in ${AccountList}; do
echo "Working on Account: ${account}"
rm -rf /Users/${account}/Library/Application Support/Google/Chrome
done
</code>


The hash # got chopped off of the front of the !/bin/bash



This should say: hash!/bin/bash where hash = #


Line spacing also got mangled up.. too
Perhaps someone can advise on the recommended syntax for posting in-line code, so that is does not to get mangled up.. ?



the section starting rm should be on a new line.


I would test this before sending it out, but this should work for you what you're looking to do:



#!/bin/sh

#Last tested on 10.10.5
userList=$(dscl . -list /Users | grep -v "_" | grep -v "daemon" | grep -v "nobody" | grep -v "root" | awk -F '/' '{print $NF}')

#Deleting Chrome Preferences
for a in $userList ; do
rm -rf /Users/"$a"/Library/Application Support/Google/Chrome
done

@PeterClarke if you highlight your code then use the >_ button it will properly format your code so nothing gets lost. You can also place three back ticks ``` on the line above and below your code to manually mark the section. You can edit your post above and fix it if you like.


Thanks to all of you for the replies. @PeterClarke that makes sense, thanks for the explanation.



I've ended up using the script posted by @jjones and it seems to be working perfectly on 10.11.6. I've yet to try on 10.12 but it seems as though it'll work as long as Google don't start changing their directory structure.


Reply