Linux finds all directories and files separately, and batches all subdirectories or files under the directory.

In order to secure flagship, we assign 755 permissions to a directory. But when you accidentally change the directory to other permissions and then want to change back to 755, it’s a bit troublesome, especially if there are multiple sub-directories under the directory. The following is quick A simple way to change: (use the powerful find command) 

写在最前,以下例子均假设要更改的目录名为test.

1.递归找出目录下所有的子目录并该将目录的权限改为755
  
  find /test -type d -exec chmod 755 {} \;

2.递归找出目录下所有的文件并将文件权限改为644

  find /path -type f -exec chmod 644 {} \;

3.不递归查找只找目录下的直接子目录
  find /path -maxdepth 1 -type d -exec chmod 755 {} \;

参数解释:
-type: 筛选文件的类型,f表示文件,d表示目录
-exec: 后面跟着要对文件执行的shell命令 
       {}符号用于表示前面条件匹配到的结果,注意一定两旁一定要有空格不然会报错
       \; 表示shell命令结束
-maxdepth:表示寻找的深度

 

Guess you like

Origin blog.csdn.net/weixin_37281289/article/details/104313363