0

i m trying to find all readable directories and subdurectories on Linux server using shell command , i have tried this command line:

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

but this command line show me just the readable folders in (/) directories and not subdirectories too.

I want to do that using php or command line

thank you

Pedro Lobito
  • 94,083
  • 31
  • 258
  • 268
walidz
  • 35
  • 6
  • 2
    If you want subdirectories, just remove `-maxdepth 1` – that other guy May 13 '16 at 23:56
  • good idea i find list of directories when apply this command line but when i want to access or read this directori it tell me that ( Can't open this folder! ) is ther any idea to do it with php script like jumping or somthing like that – walidz May 14 '16 at 00:14
  • Its good idea to mark answers as correct and not posting comments as answers -> ~http://stackoverflow.com/a/37220868/797495 . I may want to delete those "answers" or you'll get downvoted ;) – Pedro Lobito May 14 '16 at 00:39
  • Sir excuse me cuz im new hear – walidz May 14 '16 at 00:41
  • NP, we like to keep SO organized, so future users gets proper help ;) – Pedro Lobito May 14 '16 at 00:42

1 Answers1

0

"but this command line show me just the readable folders in ( / ) directories and not subdirectories too"

When you set -maxdepth 1 you're restricting the find command to /home only, remove it to allow find to search recursively.

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

If you need a native php solution, you can use this glob_recursive function and is_writable, i.e.:

<?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";
    }
}
Pedro Lobito
  • 94,083
  • 31
  • 258
  • 268