How to change permissions for a folder and its subfolders/files in one step?

后端 未结 19 1792
情歌与酒
情歌与酒 2020-11-22 13:20

I would like to change permissions of a folder and all its sub folders and files in one step (command) in Linux.

I have already tried the below command but it works

相关标签:
19条回答
  • 2020-11-22 14:02

    Check the -R option

    chmod -R <permissionsettings> <dirname>

    In the future, you can save a lot of time by checking the man page first:

    man <command name>
    

    So in this case:

    man chmod
    
    0 讨论(0)
  • 2020-11-22 14:02

    You can use -R with chmod for recursive traversal of all files and subfolders.

    You might need sudo as it depends on LAMP being installed by the current user or another one:

    sudo chmod -R 755 /opt/lampp/htdocs
    
    0 讨论(0)
  • 2020-11-22 14:03

    You want to make sure that appropriate files and directories are chmod-ed/permissions for those are appropriate. For all directories you want

    find /opt/lampp/htdocs -type d -exec chmod 711 {} \;
    

    And for all the images, JavaScript, CSS, HTML...well, you shouldn't execute them. So use

    chmod 644 img/* js/* html/*
    

    But for all the logic code (for instance PHP code), you should set permissions such that the user can't see that code:

    chmod 600 file
    
    0 讨论(0)
  • 2020-11-22 14:04

    You can change permission by using following commands

    sudo chmod go=rwx /opt/lampp/htdocs
    
    0 讨论(0)
  • 2020-11-22 14:05

    For Mac OS X 10.7 (Lion), it is:

    chmod -R 755 /directory
    

    And yes, as all other say, be careful when doing this.

    0 讨论(0)
  • 2020-11-22 14:06

    chmod -R 755 directory_name works, but how would you keep new files to 755 also? The file's permissions becomes the default permission.

    0 讨论(0)
提交回复
热议问题