Hi Floppers,
I wrote a little script a while back that allows you to recursively change permissions on a directory tree in unix, specifying permissions for either directories or files or both.
From the documentation:
I wrote a little script a while back that allows you to recursively change permissions on a directory tree in unix, specifying permissions for either directories or files or both.
From the documentation:
# Takes a path to recurse through and options for specifying directory and/or # file permissions. # Outputs a list of affected directories and files. # # If no options are specified, it recursively resets all directory and file # permissions to the default for most OSs (dirs: 755, files: 644).
Check out chmodr.sh from Gist and feel free to tinker, comment or just use as you wish.
This is VERY useful for VERY lazy people like me. Thanks!
ReplyDeleteFoudn this with google. Unfortunately, the script does not work as intended, as the getopts is executed before the PATH variable is set, so either the usage information needs to change or the PATH variable is set first and a shift operation executed so that getopts finds the options.
ReplyDeleteAlso, I am wondering if there is an advantage to replacing
ReplyDeletefind $ROOT -type d | xargs chmod -v $DIRPERMS
by
find $ROOT -type d -exec chmod $DIRPERMS {} \;
Does this avoid any command line string length limitations of the shell?
a space in file/directory name causes an error. Thanks for the script, it will make my life easier.
ReplyDeletethis should take care of spaces. Appeared to work.
ReplyDelete# Recursively set directory/file permissions based on the permission variables
if [ -n "$DIRPERMS" ] ; then
find $ROOT -type d -print0 | xargs -0 chmod -v $DIRPERMS
fi
if [ -n "$FILEPERMS" ] ; then
find $ROOT -type f -print0 | xargs -0 chmod -v $FILEPERMS
fi
Sounds good, I updated the gist to include your changes.
ReplyDeleteThanks mate!
usage is wrong order. this works:
ReplyDelete[code]
#!/bin/sh
#
# chmodr.sh
#
# author: Francis Byrne
# date: 2011/02/12
#
# Generic Script for recursively setting permissions for directories and files
# to defined or default permissions using chmod.
#
# Takes a path to recurse through and options for specifying directory and/or
# file permissions.
# Outputs a list of affected directories and files.
#
# If no options are specified, it recursively resets all directory and file
# permissions to the default for most OSs (dirs: 755, files: 644).
# Usage message
usage()
{
echo "Usage: $0 -d DIRPERMS -f FILEPERMS PATH"
echo "Arguments:"
echo "PATH: path to the root directory you wish to modify permissions for"
echo "Options:"
echo " -d DIRPERMS, directory permissions"
echo " -f FILEPERMS, file permissions"
exit 1
}
# Check if user entered arguments
if [ $# -lt 1 ] ; then
"chmodr.sh" 72 lines, 1717 characters[/code]
also, just found this:http://www.linuxquestions.org/questions/aix-43/chmod-recursion-files-only-208798/
interesting
I suck. here is the pastebin
ReplyDeletehttp://pastebin.com/WW4bVMbT
Seems that the download link is down... :/
ReplyDeleteThanks mate, I've updated the link. Should be working now.
ReplyDelete