Results 1 to 3 of 3
Hi all, I need to make a script that:
recursively changes file permissions to 665 for files and 755 for directories & subfolders of $PATH$
I have thought about smth ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
- 04-17-2012 #1Just Joined!
- Join Date
- Apr 2012
- Posts
- 1
script for file permission
Hi all, I need to make a script that:
recursively changes file permissions to 665 for files and 755 for directories & subfolders of $PATH$
I have thought about smth like:
find "path/..." -type d -print0 | xargs chmod -R 755, but i dont think it can work for all paths. how can i make it work for all of them?
Any help would be appreciated.
- 04-18-2012 #2Linux User
- Join Date
- Jan 2005
- Location
- Saint Paul, MN
- Posts
- 396
when using "-print0" in the find command then the "xargs" command needs the "-0" (dash zero) option (which means before the command (in this case "chmod"). Also since find is going to find all the directories in from the starting point, the "-R" is not needed as it will apply the new permissions to all the files as well. You need to run two command lines one for the directories and a second for regular files.
- 04-18-2012 #3Linux User
- Join Date
- Nov 2008
- Location
- Tokyo, Japan
- Posts
- 258
The "find" command has the option to execute a command like "chmod". You can pass the command, arguments and the file name (only once).
The {} will be replaced by "find" with the currently matching file path, the ";" terminates the exec command and lets you specify more arguments to "find".Code:find ... -exec {} ;
However in bash shell scripting, the {} and the ; symbols have special meanings so you need to quote them.Code:find $find_params -exec chmod $mode '{}' ';'


Reply With Quote
