HDFS Shell 조작 연습

9902 단어 shell
http://trac.nchc.org.tw/cloud/wiki
Content 1. HDFS 셸 기본 동작
1.1 HDFS 디 렉 터 리 탐색
/opt/hadoop$ bin/hadoop fs -ls

1.2 HDFS 디 렉 터 리 에 자료 업로드
  • 업로드
  • /opt/hadoop$ bin/hadoop fs -put conf input
    
  • 검사
  • /opt/hadoop$ bin/hadoop fs -ls
    /opt/hadoop$ bin/hadoop fs -ls input
    

     
    1.3 HDFS 자 료 를 로 컬 디 렉 터 리 에 다운로드
  • 다운로드
  • /opt/hadoop$ bin/hadoop fs -get input fromHDFS
    
  • 검사
  • /opt/hadoop$ ls -al | grep fromHDFS
    /opt/hadoop$ ls -al fromHDFS
    

    1.4 파일 삭제
    /opt/hadoop$ bin/hadoop fs -ls input
    /opt/hadoop$ bin/hadoop fs -rm input/masters
    

    1.5 파일 직접 보기
    /opt/hadoop$ bin/hadoop fs -ls input
    /opt/hadoop$ bin/hadoop fs -cat input/slaves
    

    1.6 더 많은 명령 조작
    hadooper@vPro:/opt/hadoop$ bin/hadoop fs 
    
    Usage: java FsShell
               [-ls <path>]
               [-lsr <path>]
               [-du <path>]
               [-dus <path>]
               [-count[-q] <path>]
               [-mv <src> <dst>]
               [-cp <src> <dst>]
               [-rm <path>]
               [-rmr <path>]
               [-expunge]
               [-put <localsrc> ... <dst>]
               [-copyFromLocal <localsrc> ... <dst>]
               [-moveFromLocal <localsrc> ... <dst>]
               [-get [-ignoreCrc] [-crc] <src> <localdst>]
               [-getmerge <src> <localdst> [addnl]]
               [-cat <src>]
               [-text <src>]
               [-copyToLocal [-ignoreCrc] [-crc] <src> <localdst>]
               [-moveToLocal [-crc] <src> <localdst>]
               [-mkdir <path>]
               [-setrep [-R] [-w] <rep> <path/file>]
               [-touchz <path>]
               [-test -[ezd] <path>]
               [-stat [format] <path>]
               [-tail [-f] <file>]
               [-chmod [-R] <MODE[,MODE]... | OCTALMODE> PATH...]
               [-chown [-R] [OWNER][:[GROUP]] PATH...]
               [-chgrp [-R] GROUP PATH...]
               [-help [cmd]]
    
    Generic options supported are
    -conf <configuration file>     specify an application configuration file
    -D <property=value>            use value for given property
    -fs <local|namenode:port>      specify a namenode
    -jt <local|jobtracker:port>    specify a job tracker
    -files <comma separated list of files>    specify comma separated files to be copied to the map reduce cluster
    -libjars <comma separated list of jars>    specify comma separated jar files to include in the classpath.
    -archives <comma separated list of archives>    specify comma separated archives to be unarchived on the compute machines.
    The general command line syntax is
    bin/hadoop command [genericOptions] [commandOptions]
    
    

     
    Content 2. 웹 페이지 Gui 로 정보 조회
     
  •  Map/Reduce Administration
  •  NameNode

  •  
    Content 3. 더 많은 HDFS 셸 사용법
     
  • bin / hadop fs < args >, 다음은 < args > 의 용법
  • 을 보 여 줍 니 다.
  • 아래 에 설 치 된 디 렉 터 리 는 / user / < $username > / 아래
    $ bin/hadoop fs -ls input
    Found 4 items
    -rw-r--r--   2 hadooper supergroup  115045564 2009-04-02 11:51 /user/hadooper/input/1.txt
    -rw-r--r--   2 hadooper supergroup     987864 2009-04-02 11:51 /user/hadooper/input/2.txt
    -rw-r--r--   2 hadooper supergroup    1573048 2009-04-02 11:51 /user/hadooper/input/3.txt
    -rw-r--r--   2 hadooper supergroup   25844527 2009-04-02 11:51 /user/hadooper/input/4.txt
    
  • 에 있 습 니 다.
  • 완전한 경 로 는  hdfs://node:port/path 예 를 들 어
    $ bin/hadoop fs -ls hdfs://gm1.nchc.org.tw:9000/user/hadooper/input
    Found 4 items
    -rw-r--r--   2 hadooper supergroup  115045564 2009-04-02 11:51 /user/hadooper/input/1.txt
    -rw-r--r--   2 hadooper supergroup     987864 2009-04-02 11:51 /user/hadooper/input/2.txt
    -rw-r--r--   2 hadooper supergroup    1573048 2009-04-02 11:51 /user/hadooper/input/3.txt
    -rw-r--r--   2 hadooper supergroup   25844527 2009-04-02 11:51 /user/hadooper/input/4.txt
    
  • 이다.
    -cat
  • 경로 지정 파일 의 내용 을 stdout
    $ bin/hadoop fs -cat quota/hadoop-env.sh
    
  • 에 출력 합 니 다.
    -chgrp
  • 파일 이 속 한 그룹 변경
    $ bin/hadoop fs -chgrp -R hadooper own
    
  • -chmod
  • 파일 의 권한 변경
    $ bin/hadoop fs -chmod -R 755 own
    
  • -chown
  • 파일 변경 소유자
    $ bin/hadoop fs -chown -R hadooper own
    
  • -copyFromLocal, -put
  • local 파일 에서 hdfs
    $ bin/hadoop fs -put input dfs_input
    
  • 까지
    -copyToLocal, -get
  • hdfs 에 있 는 파일 을 local
    $ bin/hadoop fs -get dfs_input input1
    
  • 에 다운로드 합 니 다.
    -cp
  • hdfs 원래 경로 에서 hdfs 대상 경로 로 파일 복사
    $ bin/hadoop fs -cp own hadooper
    
  • -du
  • 디 렉 터 리 에 있 는 모든 파일 의 크기 표시
    $ bin/hadoop fs -du input
    
    Found 4 items
    115045564   hdfs://gm1.nchc.org.tw:9000/user/hadooper/input/1.txt
    987864      hdfs://gm1.nchc.org.tw:9000/user/hadooper/input/2.txt
    1573048     hdfs://gm1.nchc.org.tw:9000/user/hadooper/input/3.txt
    25844527    hdfs://gm1.nchc.org.tw:9000/user/hadooper/input/4.txt
    
  • -dus
  • 이 디 렉 터 리 / 파일 의 총 크기 표시
    $ bin/hadoop fs -dus input
    
    hdfs://gm1.nchc.org.tw:9000/user/hadooper/input	143451003
    
  • -expunge
  • 휴지통 비우 기
    $ bin/hadoop fs -expunge
    
  • -getmerge
  • 원본 디 렉 터 리 < src > 아래 의 모든 파일 을 로 컬 엔 드 의 < localdst > 파일 에 집합 합 니 다
  • bin/hadoop fs -getmerge
    $ echo "this is one; " >> in1/input
    $ echo "this is two; " >> in1/input2
    $ bin/hadoop fs -put in1 in1
    $ bin/hadoop fs -getmerge in1 merge.txt
    $ cat ./merge.txt
    

  • -ls
  • 파일 이나 디 렉 터 리 를 보 여 주 는 정보
  • 파일 이름 < 던 전 수 > 파일 크기 수정 날짜 수정 시간 권한 사용자 ID 그룹 ID
  • 디 렉 터 리 이름 < dir > 수정 날짜 수정 시간 권한 사용자 ID 그룹 ID
    $ bin/hadoop fs -ls
    
  • -lsr
  • ls 명령 의 반송 버 전
    $ bin/hadoop fs -lsr /
    
  • -mkdir
  • 서류철 작성
    $ bin/hadoop fs -mkdir a b c
    
  • -moveFromLocal
  • local 엔 드 의 자 료 를 잘라 hdfs 로 이동
    $ bin/hadoop fs -moveFromLocal in1 in2
    
  • -mv
  • 자료 의 명칭 변경
    $ bin/hadoop fs -mv in2 in3
    
  • -rm
  • 지정 한 파일 삭제 (서류철 불가)
    $ bin/hadoop fs -rm in1/input
    
  • -rmr
  • 폴 더 삭제 (포 함 된 모든 파일)
    $ bin/hadoop fs -rmr in1
    
  • -setrep
  • 던 전 계수 설정
  • bin/hadoop fs -setrep [-R] [-w]
    $ bin/hadoop fs -setrep -w 2 -R input 
    Replication 2 set: hdfs://gm1.nchc.org.tw:9000/user/hadooper/input/1.txt
    Replication 2 set: hdfs://gm1.nchc.org.tw:9000/user/hadooper/input/2.txt
    Replication 2 set: hdfs://gm1.nchc.org.tw:9000/user/hadooper/input/3.txt
    Replication 2 set: hdfs://gm1.nchc.org.tw:9000/user/hadooper/input/4.txt
    Waiting for hdfs://gm1.nchc.org.tw:9000/user/hadooper/input/1.txt ... done
    Waiting for hdfs://gm1.nchc.org.tw:9000/user/hadooper/input/2.txt ... done
    Waiting for hdfs://gm1.nchc.org.tw:9000/user/hadooper/input/3.txt ... done
    Waiting for hdfs://gm1.nchc.org.tw:9000/user/hadooper/input/4.txt ... done
    

  • -stat
  • 인쇄 시간 정보
    $ bin/hadoop fs -stat input
    2009-04-02 03:51:29
    
  • -tail
  • 파일 의 마지막 1k 내용 을 출력 합 니 다
  • 용법: bin / hadop fs - tail [- f] 파일 (- f 매개 변 수 는 파일 이 커지 면 append 에 있 는 내용 을 표시 합 니 다)
    $ bin/hadoop fs -tail input/1.txt
    
  • -test
  • 테스트 파일, - e 파일 이 존재 하 는 지 확인 (1 = 존재 하 는 지, 0 = 여부), - z 파일 이 비어 있 는 지 확인 (1 = 비어 있 는 지, 0 = 비어 있 지 않 은 지), - d 디 렉 터 리 인지 확인 (1 = 존재 하 는 지, 0 = 없 는 지)
  • echo $를 사용 하 시 겠 습 니까?리 턴 값 을 보면 0 or 1
  • 용법: bin / hadop fs - test - [ezd] URI
  •  
    $ bin/hadoop fs -test -e /user/hadooper/input/5.txt
    $ bin/hadoop fs -test -z /user/hadooper/input/5.txt
    test: File does not exist: /user/hadooper/input/5.txt
    $ bin/hadoop fs -test -d /user/hadooper/input/5.txt
    
    test: File does not exist: /user/hadooper/input/5.txt
    

    -text
  • 파일 (예 를 들 어 압축 파일, textrecordinputstream) 을 일반 텍스트 형식 으로 출력 합 니 다
  • hadoop fs -text
    $ hadoop fs -text macadr-eth1.txt.gz
    00:1b:fc:61:75:b1
    00:1b:fc:58:9c:23
    
  • ps: 현재 zip 를 지원 하지 않 은 함 식 라 이브 러 리
    $ bin/hadoop fs -text b/a.txt.zip
    PK
    ���:��H{
            a.txtUT	b��Ib��IUx��sssss
    test
    PK
    ���:��H{
    ��a.txtUTb��IUxPK@C
    
  • -touchz
  • 빈 파일 만 들 기
    $ bin/hadoop fs -touchz b/kk
    $ bin/hadoop fs -test -z b/kk
    $ echo $?
    1
    $ bin/hadoop fs -test -z b/a.txt.zip
    $ echo $?
    0
    
  • 좋은 웹페이지 즐겨찾기