如何找到在Linux上读取文件夹

问题描述:

即时试图找到使用shell命令Linux服务器上的所有可读的目录和subdurectories, 我已经试过此命令行:如何找到在Linux上读取文件夹

find /home -maxdepth 1 -type d -perm -o=r 

,但这个命令行告诉我只是可读(/)目录中的文件夹,而不是子目录。

我想这样做,使用PHP或命令行

谢谢

+2

如果你想子目录,只是删除'-maxdepth 1' –

+0

好主意我找到应用此命令行时的目录列表,但是当我想要访问或阅读此导演时,它告诉我(无法打开此文件夹!) 其他想法做到这一点与PHP脚本像跳跃或类似的东西 – walidz

+0

它是一个好主意,以标记答案是正确的,而不是张贴评论作为答案 - >〜http://*.com/a/372​​20868/797495。我可能想删除这些“答案”,否则你会得到downvoted;) –

但这个命令行告诉我刚刚在(/) 目录中读取文件夹,而不是子目录太

当您设置-maxdepth 1时,您将find命令限制为/home只,删除它允许找到搜索递归

find /home -type d -perm -o=r 

如果你需要一个本地php解决方案,您可以使用此功能glob_recursiveis_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"; 
    } 
} 
+0

是的先生谢谢 – walidz