How to recursively change permissions on all directories inside current directory?

14,196

Solution 1

You're missing a space after 644.

Also, 644 is probably not what you want on a directory. You probably want 755.

Edit to include answer from comments below:

For directories:

find . -type d -exec chmod 755 {} \;

For files:

find . -type f -exec chmod 644 {} \;

There's very likely other ways (maybe shorter) to do this, but this will work.

Solution 2

Another way to do this is:

chmod -R u=rwX,g=rX,o=rX /path/to/dir

The capital X is a conditional execute- if the file is a directory the execute bit gets added OR if the file is already executable the execute bit gets retained.

Though this would add permissions to non directory files. If these permissions are acceptable, this works for quickly adding access to folders.

Share:
14,196

Related videos on Youtube

Alan Kis
Author by

Alan Kis

Updated on September 18, 2022

Comments

  • Alan Kis
    Alan Kis over 1 year

    How can I change folder and file permissions for all files and folders recursively inside current directory? I am not sure, why, but my command fails with this

    output: chmod: missing operand after '644./components/path/path/path'

    My command is:

    find . * -type d -exec chmod 755{} \;
    

    As user pdo pointed, I want change folder permissions to 755-

  • Alan Kis
    Alan Kis over 8 years
    Yes, I want to 755. Now I got find: '.', '*' .Permission denied, and failed to restore initial working directory.
  • Geoff
    Geoff over 8 years
    What are the permissions on the current working directory?
  • Paul Calabro
    Paul Calabro over 8 years
    Prefix the command with sudo and it should work if you have permission to do so.
  • roaima
    roaima over 8 years
    You mgiht want to add this (or something like it) to your answer to make your suggestion explicit: find . -type d -exec chmod 755 {} +
  • Alan Kis
    Alan Kis over 8 years
    @pdo, current working directory is 750. I am not root, this is jailed cPanel shell.
  • Geoff
    Geoff over 8 years
    @AlanKis let's restate the problem: you want to change the permissions on all directories under the current working directory to 755?
  • Alan Kis
    Alan Kis over 8 years
    @pdo, exactly, and files to 644.
  • Geoff
    Geoff over 8 years
    @AlanKis ok, so: find . -type d -exec chmod 755 {} \; for the directories, and find . -type f -exec chmod 644 {} \;
  • Alberto Salvia Novella
    Alberto Salvia Novella almost 3 years
    This works 👍👍