CartMetrix - Do you know yours?

« DLoads Pepper Released | Home | The Other Costs of Hurricane Rita »

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 rchown='chown --reference '
alias rchmod='chmod --reference '

To use:

rchown referencefile *
rchmod referencefile *

Or put it all together in a shell script refch.sh:

#!/bin/bash

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

Download refch.sh

To use:

refch.sh referencefile adminfile
refch.sh referencefile . -R

The '-R' option means recursive, or act on every selected file in this directory and every subdirectory recursively.

Popularity: 12%

Trackback:

Related Posts

Post your opinion

Verification Image

Please type the letters you see in the picture.

Subscribe without commenting


damonparker.org is proudly powered by WordPress
Entries (RSS) and Comments (RSS).

copyright © 2002-2008 damonparker.org. all rights reserved.

Close
E-mail It