在 Linux 中,可以使用 find 命令结合 chmod 命令来批量修改文件权限。以下是一些示例:
find /path/to/directory -type f -exec chmod 644 {} \;
这个命令会在 /path/to/directory 目录下查找所有文件(不包括子目录),并将它们的权限设置为 644(即 -rw-r--r--)。
find /path/to/directory -type d -exec chmod 755 {} \;
find /path/to/directory -type f -exec chmod 644 {} \;
第一个命令会修改 /path/to/directory 下所有子目录的权限为 755(即 drwxr-xr-x),第二个命令会修改所有文件的权限为 644。
find /path/to/directory -type d -not -path '/path/to/directory/exclude_dir' -exec chmod 755 {} \;
find /path/to/directory -type f -not -path '/path/to/directory/exclude_dir/*' -exec chmod 644 {} \;
这两个命令分别修改 /path/to/directory 下所有子目录(排除 exclude_dir)和文件(排除 exclude_dir 下的文件)的权限。
注意:在执行这些命令之前,请确保你了解它们的作用,并在实际环境中进行测试。错误的权限设置可能导致系统安全问题或应用程序无法正常运行。