1836643 Members
1666 Online
110102 Solutions
New Discussion

Re: change file mode

 
addendum
Advisor

change file mode

If I want to change all the file mode of a specific user under all directories ( eg. edp_user ) , what can I do ? thx
4 REPLIES 4
Arunvijai_4
Honored Contributor

Re: change file mode

chmod -R will help.

-Arun
"A ship in the harbor is safe, but that is not what ships are built for"
RAC_1
Honored Contributor

Re: change file mode

find /dir -type f -user edp_user -exec chmod "perms" {} \;

find /dir -type d -user edp_user -exec chmod "perms" {} \;

Anil
There is no substitute to HARDWORK
addendum
Advisor

Re: change file mode

It is OK , thx
Roboz
Frequent Advisor

Re: change file mode

Hello there: A couple of things to think about. While it is true that you can use the recursive option in chmod (i.e. chmod -R) as pointed out before please keep in mind this:
a) All the files in the path you select will be changed, including any subdirectory that may be part of the given path. You may have to redo subdirectories to reflect the correct permissions for them.
b) Only root and the owner of the file can change the mode. Make sure your UID is the owner of the files. Alternatively you can login as root.
c) You may want to use the script below after you test it to help you with the task (no guaranties of any kind). Best of luck
SCRIPT ----------------------
#! /usr/bin/sh
ARGS=$#
ARG0=$0
ARG1=$1
ARG2=$2
ARG3=$3

usg_msg()
{
echo "\n$1 \n
usage: $ARG0 arg1 arg2 arg3
arg1 = directory_namename (relative or absolute)
arg2 = new mode for the files in the directory
arg3 = new mode for subdirectories
(all arguments must must be entered)
"
}

tst_arg()
{
if [ $ARGS -ne 3 ]
then
echo $#
usg_msg "Invalid number of arguments"
exit 1
fi
if [ -d $ARG1 ]
then
DIRPATH=$ARG1
else
usg_msg "Invalid directory path"
exit 1
fi
if (echo $ARG2 | grep "[a-zA-Z]" > /dev/null)
then
usg_msg "$ARG2 Invalid mode"
exit 1
else
FILEPERM=$ARG2 #set this variable to the mode for ordinary files
fi
if (echo $ARG3 | grep "[a-zA-Z]" > /dev/null)
then
usg_msg "$ARG3 Invalid mode"
exit 1
else
DIRPERMS=$ARG3 #set this to the mode required for subdirectories
fi
}

tst_arg
echo $DIRPATH $FILEPERM $DIRPERMS
read nothing
for afile in $(find $DIRPATH)
do
if test -d $afile
then
chmod $DIRPERMS $afile
else
chmod $FILEPERM $afile
fi
done