Find the answer to your Linux question:
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.
  1. #1
    Just 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.

  2. #2
    Linux Enthusiast
    Join Date
    Jan 2005
    Location
    Saint Paul, MN
    Posts
    627
    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.

  3. #3
    Linux User
    Join Date
    Nov 2008
    Location
    Tokyo, Japan
    Posts
    260
    The "find" command has the option to execute a command like "chmod". You can pass the command, arguments and the file name (only once).
    Code:
    find ... -exec {} ;
    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".

    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 '{}' ';'

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •