# Unix/OS X: CHOWN recursively but selectively

**URL:** <https://boards.straightdope.com/t/unix-os-x-chown-recursively-but-selectively/441524>\
**Category:** Factual Questions\
**Created:** [March 16, 2008, 3:40am UTC](https://boards.straightdope.com/t/unix-os-x-chown-recursively-but-selectively/441524 "2008-03-16T03:40:36Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![The\_Shroud](https://avatars.discourse-cdn.com/v4/letter/t/439d5e/32.png) [@The\_Shroud](https://boards.straightdope.com/u/The_Shroud)\
**Post date:** [March 16, 2008, 3:40am UTC](https://boards.straightdope.com/t/unix-os-x-chown-recursively-but-selectively/441524/1 "2008-03-16T03:40:36Z")

</div>

I’m having issues in OS X; for various reasons, a bunch of my Apps are owned by a different Admin user, one I never log in as. Most of the time this is a non-issue; just have to type in a password to monkey with the files. But it’s caused a few problems, and I’d like to get them all on the same page.

However, there are also apps in /Applications which are owned by root. I figure I shouldn’t change those.

So, is there a script I can run that will check to see which files are owned by the old user and only change ownership on those?

---

<div class="post-metadata">

**Author:** ![Rysto](https://avatars.discourse-cdn.com/v4/letter/r/ecccb3/32.png) [@Rysto](https://boards.straightdope.com/u/Rysto)\
**Post date:** [March 16, 2008, 5:01am UTC](https://boards.straightdope.com/t/unix-os-x-chown-recursively-but-selectively/441524/2 "2008-03-16T05:01:21Z")

</div>

chown new\_user:new\_group `find /Applications -user old_user`

---

<div class="post-metadata">

**Author:** ![The\_Shroud](https://avatars.discourse-cdn.com/v4/letter/t/439d5e/32.png) [@The\_Shroud](https://boards.straightdope.com/u/The_Shroud)\
**Post date:** [March 16, 2008, 5:58am UTC](https://boards.straightdope.com/t/unix-os-x-chown-recursively-but-selectively/441524/3 "2008-03-16T05:58:46Z")

</div>

Thanks! You got me off on the right track. Everything I tried gave me a “too many arguments” error of some variety, but I managed to come up with this beast that worked:

sudo find . -user olduser -print0 | xargs -0 -L100 sudo chown -R newuser

Whew.

---

<div class="post-metadata">

**Author:** ![TimeWinder](https://avatars.discourse-cdn.com/v4/letter/t/bcef8e/32.png) [@TimeWinder](https://boards.straightdope.com/u/TimeWinder)\
**Post date:** [March 16, 2008, 9:53am UTC](https://boards.straightdope.com/t/unix-os-x-chown-recursively-but-selectively/441524/4 "2008-03-16T09:53:41Z")

</div>

I presume you’ve also used the Disk Utility’s “Repair Permissions” feature? It deals with a wide range of these sorts of things without having to go to a command line, although it’s exact behaviour is a little mysterious.

---

<div class="post-metadata">

**Author:** ![Derleth](https://avatars.discourse-cdn.com/v4/letter/d/b9e5f3/32.png) [@Derleth](https://boards.straightdope.com/u/Derleth)\
**Post date:** [March 16, 2008, 11:00am UTC](https://boards.straightdope.com/t/unix-os-x-chown-recursively-but-selectively/441524/5 "2008-03-16T11:00:02Z")

</div>

[QUOTE=TimeWinder]  
I presume you’ve also used the Disk Utility’s “Repair Permissions” feature? It deals with a wide range of these sorts of things without having to go to a command line, although it’s exact behaviour is a little mysterious.  
[/QUOTE]  
And the command line’s behavior is not mysterious at all. When modifying essential parts of your system, mystery is your enemy.

---

<div class="post-metadata">

**Author:** ![minor7flat5](https://sea3.discourse-cdn.com/straightdope/user_avatar/boards.straightdope.com/minor7flat5/32/258_2.png) [@minor7flat5](https://boards.straightdope.com/u/minor7flat5)\
**Post date:** [March 16, 2008, 5:44pm UTC](https://boards.straightdope.com/t/unix-os-x-chown-recursively-but-selectively/441524/6 "2008-03-16T17:44:00Z")

</div>

[QUOTE=The Shroud]  
Thanks! You got me off on the right track. Everything I tried gave me a “too many arguments” error of some variety, but I managed to come up with this beast that worked:

sudo find . -user olduser -print0 | xargs -0 -L100 sudo chown -R newuser

Whew.  
[/QUOTE]  
This is the format I use for all things “find”:

find . [filters] -exec [command] {} ;

Like this:

sudo find . -user olduser -exec chown newuser {} ;

This uses the “-exec” switch of the “find” command. Just put the curly braces wherever you want the individual files found to go in the command string, and remember to put the backslash-semicolon at the end of the command.

The command in “-exec” will be executed once per line produced by “find”
