Find the answer to your Linux question:
Results 1 to 3 of 3
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #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 Engineer
    Join Date
    Jan 2005
    Saint Paul, MN
    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
    Tokyo, Japan
    The "find" command has the option to execute a command like "chmod". You can pass the command, arguments and the file name (only once).
    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.
    find $find_params -exec chmod $mode '{}' ';'

  4. $spacer_open

Posting Permissions

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