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?
Answer
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[@]}"
No comments:
Post a Comment