Script to set file permissions on a shared document tree

When using a shared document tree you probably want to keep the the same groupid when saving and creating documents. To do this you set a sticky bit on the folder. I wrote a script to set/correct the permissions in a shared older.

#! /bin/sh
# shellscript to set user permissions on files and folders
# it also sets a sticky bit for the group on all subfolders
# primarily for use on shared folders

if [ "$1" != "" ] && [ "$2" != "" ]; then
        echo "Setting file group..."
        find "$1" -type f -print0 |xargs -0 chown :"$2"
	echo "Setting file permissions..."
	find "$1" -type f -print0 |xargs -0 chmod 660
	echo "Setting folder group..."
	find "$1" -type d -print0 |xargs -0 chown :"$2"
	echo "Setting folder permissions..."
	find "$1" -type d -print0 |xargs -0 chmod 2770
else
	echo "USAGE:"
	echo "    xperm PATH GROUP"
fi
Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *