我试图使用shell命令在Linux服务器上查找所有可读目录和子程序,我尝试了以下命令行:
find /home -maxdepth 1 -type d -perm -o=r但是这个命令行只显示了(/)目录中的可读文件夹,而不是子目录。
我想使用php或命令行来完成这个任务。
谢谢
发布于 2016-05-13 23:59:22
“,但这个命令行只显示(/)目录中的可读文件夹,而不是子目录太”
当您将-maxdepth 1设置为仅限/home命令时,将其移除以允许查找递归搜索。
find /home -type d -perm -o=r如果需要本机php解决方案,可以使用此glob_recursive函数和is_writable,即:
<?php
function rglob($pattern, $flags = 0) {
$files = glob($pattern, $flags);
foreach (glob(dirname($pattern).'/*', GLOB_ONLYDIR|GLOB_NOSORT) as $dir) {
$files = array_merge($files, rglob($dir.'/'.basename($pattern), $flags));
}
return $files;
}
$dirs = rglob('/home/*', GLOB_ONLYDIR);
foreach( $dirs as $dir){
if(is_writable($dir)){
echo "$dir is writable.\n";
}
}https://stackoverflow.com/questions/37220949
复制相似问题