Usually those files get wrong permission when coming from the network, even when I copy them from it, but mostly through "file sharing". So, definitely not talking about Disk Utility repair here, please.

But regardless of how the file got wrong permission, I know of two bad ways to fix them. One is CMD+I and the other is chown / chmod. The command line isn't all bad but isn't practical either.

Some times it's just 1 file I need to repair, sometimes it's a bunch of them. By "repair" I mean 644 for files, 755 for folders, and current user:group for all of them.

Isn't there any app / script / automator out there to do that?

link|improve this question

68% accept rate
feedback

1 Answer

up vote 3 down vote accepted

Here's a script for you. I haven't tested this, so I'm going to set this Answer as a community wiki so others can fix my errors and infelicities.

#!/bin/bash

# Description: Fix file permissions like Cawas likes.

# TFILES is an array of target files.
TFILES=("$@")

# TUSER is the target user you want the files to be owned by
TUSER=$(id -u)

# TGROUP is the target group you want set on the files
TGROUP=$(id -g)

# chown everything to user:group:
sudo chown -R ${TUSER}:${TGROUP} "${TFILES[@]}"

# chmod to 644 for files, 755 for directories
sudo chmod -R u=rwX,go=rX "${TFILES[@]}"
link|improve this answer
Thanks to @Gordon Davisson for fixing my array syntax and finding a way around using find(1). I wasn't aware of chmod(1)'s capital-X notation. I added a -R back in that is needed if you're not using find(1). – Spiff May 21 '10 at 18:48
That script looks great and works fine, Spiff. I also didn't know about capital X and that's great stuff! It's already easier using it than my current methods. But... I still hope someone can come up with an even more automated way, such as service (to do it with right click) or something drag n' drop, as to avoid the extra step of having to go to the dreaded Terminal. :) – Cawas May 23 '10 at 5:45
feedback

Your Answer

 
or
required, but never shown

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