ABOUT ME

-

Today
-
Yesterday
-
Total
-
  • ls 명령어 디렉토리만 확인하는 방법에 대하여
    2011. 11. 2. comments

    ls 명령어는 파일과 디렉토리 리스트를 출력해주는 unix계열의 명령어다. ls --help 명령어를 확인하면 -d 옵션으로 directory만 출력하게 하는 옵션을 확인할 수 있다.

    morenice@ubuntu:~$ ls --help
    
    사용법: ls [<옵션>]... [<파일>]...
    List information about the FILEs (the current directory by default).
    Sort entries alphabetically if none of -cftuvSUX nor --sort.
    
    긴 옵션에서 꼭 필요한 인수는 짧은 옵션에도 꼭 필요합니다.
      -a, --all                  do not ignore entries starting with .
      -A, --almost-all           do not list implied . and ..
    
    ..
      -d, --directory            list directory entries instead of contents,
                                   and do not dereference symbolic links
    ..
    ..
    


    하지만 실제로 ls -d 명령을 실행하면 디렉토리가 출력되지 않고 . 하나만 출력된다.

    morenice@ubuntu:~$ ls -d
    .
    


    google 에서 간단한 내용을 검색해보니 외쿡 사람들도 왜 출력이 안되지 하면서 논의한 사항들이 있다.

    http://embraceubuntu.com/2005/10/19/list-only-the-directories/ 


    위의 사이트의 몇가지 사용예가 있다.

    ls -d 

    •  ls -d */ 
    •  ls -d */ | xargs -l basename


    아!! ls -d 혹은 ls -d * 을 하면 결과가 안나오고 ls -d */을 해야 디렉토리만 출력된다.
    스크립트를 사용할 경우에는 ls -d */ | xargs -l basename 를 사용하는게 편리할 것이다.



    find 


    •  find ./ -type d -maxdepth 1 -mindepth 1



    세부 디렉토리까지 검색하려면 -depth 옵션들을 빼주면 된다.



    tree


    • tree -d -L 1

     
    사용자 입장으로써 눈으로 보기에는 tree를 사용하는 편이 좋다.


    반응형

    댓글

Designed by Tistory.