I changed the shortname of my user account, but it seems to have caused an issue with some files (especially homebrew stuff), which are still owned by the old username. My old short name was cannyboy, and my new one is cannyman. How would I go thru the whole hard drive and change ownership of all cannyboy to cannyman, without changing any other attributes of the files?


2 Answers 2


As starter I would suggest you run the "repair permission" function in disk utility.

If the problem still persists you could run a command like:

find . -user old_user | while read file; do echo chown new_user  $file; done

note: this doesn't do anything as is now - you will need to adjust it to your needs - and make sure it does nothing bad.

update learnt some more and now I would run a command like this:

find . -user old_user -print0 | xargs -0  sudo echo chown new_user

again adjust the command before you run it!

  • I tried to run the command as find . -user old_user | while read file; do chown new_user \"$file\"; done but it does not work with files with spaces. how do we achieve this command with files with spaces ?
    – Laxman
    Aug 21, 2018 at 17:00
  • 1
    I added the line as I would do it nowadays - that works even with spaces and weird characters.
    – bdecaf
    Aug 22, 2018 at 8:23

FWIW changing the short name is considered "bad." Guess you can see why now.

That said, one way to deal with this is to use "find" to locate all the files owned by cannyboy:

find * -user cannyboy

(for just homebrew you could limit this to the /usr/local/ folder hierarchy like):

find -f /usr/local/* -user cannyboy

Next loop through the results with:

sudo chown cannyboy cannyman *file*

note the above command will require sudo and if you mess up could cause further problems.

To do this in a two step process, first:

find -f /usr/local/* -user cannyboy > files.txt

Then loop through files.txt using the following script (with sudo):


while read file;
    chown cannyboy cannyman $file

The advantage of this is you can use a subset of your txt file to test everything before you commit to a massive change.

If you are brave, you can try the one step process (this should work, but it might not):

for result in `find -f /usr/local/* -user cannyboy`
    chown cannyboy cannyman $result

(BTW prior to Mac OS X 10.8.1 there was a nasty find bug that would omit some results)

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .