9/21/2005
Chown/Chmod Files By Reference
Working on shared server, you can easily create files under a user's account with root or admin privileges, leaving the user with no way to edit or delete the files. Drop the following alias' into your .bashrc so you can easily chown and chmod to the user's user, group and permissions by referencing a file.
alias rchmod='chmod --reference '
To use:
rchmod referencefile *
Or put it all together in a shell script refch.sh:
if [ "$#" -lt 2 ]; then
echo "Usage: `basename $0` referencefile files [params]";
exit 1
fi
chown $3 --reference $1 $2
chmod $3 --reference $1 $2
if [[ "$3" = *R* ]]; then
chmod $3 +X $2
fi
exit 0
To use:
refch.sh referencefile . -R
The '-R' option means recursive, or act on every selected file in this directory and every subdirectory recursively.
Popularity: 12%


