2012-08-30 1 views
1

나는 익숙하지 않은 리눅스 머신으로 작업하고있다. 그래서 폴더 구조에서 txt 프린트를 얻고 싶다. 나는 PHP에서 비슷한 것을하는 스크립트를 작성했지만 그것을 찾을 수 없다는 것을 기억합니다. 그러나bash 나 php로 폴더 계층 구조를 얻는 것

  • 떠들썩한 파티 스크립트
  • 기존 리눅스 명령 라인
  • PHP 스크립트
+0

당신이'find' 명령을 시도 했습니까? – Mat

답변

4
find . -type d > dirstructure.txt 

:이 작업을 도와 수 있다는 다음 중 하나를 찾고 있어요 typcial 리눅스 박스에서, 나는 디렉토리 루트에서 이것을 실행하지 않을 것이다. 당신이하고 권한 오류의 몇 가지를 얻을 경우,이 시도 /dev/null

find . -type d > dirstructure.txt 2> /dev/null 
+1

-maxdepth #를 추가하면 디렉토리 구조가 너무 깊어지고 싶지 않을 때 유용합니다. 두 단계 만 표시하려면'find. -maxdepth 2 -type d' – Brett

0

에 오류를 보낼 수 있을까?

ls -R | grep ":$" | sed -e 's/:$//' -e 's/[^-][^\/]*\//--/g' -e 's/^/ /' -e 's/-/|/' 

http://www.centerkey.com/tree/

1

빠른에서 가져온 더러운 :

class Crawl_directory 
{ 
    public $exclude = array(); 
    public $paths = array(); 
    public $tree = FALSE; 
    public $tree_str = FALSE; 
    public function __construct($path, $exclude = array()) 
{ 
     if (!$path || !is_dir($path)) 
      return FALSE; 
     $this->exclude = array_merge(array(), $exclude); 
     $this->tree = $this->crawl($path); 
     $this->tree_str = $this->create_tree($this->tree); 
} 
    public function crawl($path) 
    { 
     $arr = array(); 
     $items = scandir($path); 
     $this->paths[] = $path; 
     foreach ($items as $k => $v) { 
      if (!in_array($v, $this->exclude) && $v != '.' && $v != '..') { 
       if (is_dir($path.'/'.$v)) { 
        $arr[$v] = $this->crawl($path.'/'.$v); 
       } else { 
        $arr[$v] = ''; 
       } 
      } 
     } 
     return $arr; 
    } 
    function create_tree($arr) 
    { 
     $out = '<ul>'."\n"; 
     foreach ($arr as $k => $v) { 
      $out .= '<li class="'.((is_array($v)) ? 'folder' : 'file').'">'.$k.'</li>'."\n"; 
      if (is_array($v)) { 
       $out .= $this->create_tree($v); 
      } 
     } 
     $out .= '</ul>'."\n"; 
     return $out;  
    } 
    function get_tree() 
    { 
     return $this->tree; 
     } 
    function print_tree() 
    { 
     echo $this->tree_str; 
    } 
} 
관련 문제