How to change file permission of multiple files at once using chmod?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • webandwe
    New Member
    • Oct 2006
    • 142

    How to change file permission of multiple files at once using chmod?

    Hi,

    I am trying now for the last 2 weeks to get a $!*@ script to change all my files under one folder to 644.

    Can someone please help me or just give me a script you have cause I am now fed up with this stuff not wanting to work.

    Thank-you

    [PHP]
    $file = all my files in my images folder or this directory


    $old = umask(0);
    chmod("$file", 0644);
    umask($old);

    // Checking
    if ($old != umask()) {
    die('An error occured while changing back the umask');
    }
    [/PHP]
  • kovik
    Recognized Expert Top Contributor
    • Jun 2007
    • 1044

    #2
    Look into the directory functions.

    Comment

    • psylem
      New Member
      • Sep 2007
      • 1

      #3
      I was having the same issue. I don't know how you do it with PHP, but this command worked for me...

      find /var/www/html/*/ -type d -exec chmod 755 {}/*.php \;

      It changes the permissions of all php files in the html directory. You may want to also change the permissions on the directories them selves as well, in which case run this one too...

      find /var/www/html/*/ -type d -exec chmod 755 {} \;

      Comment

      Working...