Skip to content

Modify file permissions in batches on Linux

During use, you often encounter the following situations: It is necessary to modify the folder permissions in a certain directory to: 0755, the owner is root, the file permissions are: 0644, the owner is root

1. Set the permissions of all folders in a directory individually```

find -type d -exec chmod 0755 {} \;

## 2. Set the permissions of all files in a directory individually```
find -not -type d -exec chmod 644 {} \;

3. If you want to set the owner of the folder individually, you only need to change the command to the following:

find -type d -exec chown root.root {} \;

Add- Scope of authority: ```

    u :目录或者文件的当前的用户
    g :目录或者文件的当前的群组
    o :除了目录或者文件的当前用户或群组之外的用户或者群组
    a :所有的用户及群组
```
  • Permission code: r :读权限,用数字4表示 w :写权限,用数字2表示 x :执行权限,用数字1表示 – :删除权限,用数字0表示 s :特殊权限

REF[1].https://justcode.ikeepstudying.com/2018/01/linux-%E6%89%B9%E9%87%8F%E4%BF%AE%E6%94%B9%E6%96%87%E4%BB%B6%E 5%A4%B9%E3%80%81%E6%96%87%E4%BB%B6%E7%9A%84%E6%9D%83%E9%99%90%E5%92%8C%E6%89%80%E6%9C%89%E8%80%85chmod-chown/