Programing

HDFS 디렉토리의 크기를 확인하는 방법은 무엇입니까?

lottogame 2020. 9. 17. 18:53
반응형

HDFS 디렉토리의 크기를 확인하는 방법은 무엇입니까?


나는 du -sh일반적인 Linux 파일 시스템을 알고 있습니다. 하지만 HDFS로 어떻게할까요?


0.20.203 이전 및 2.6.0에서 공식적으로 지원 중단 :

hadoop fs -dus [directory]

이후 0.20.203 (죽은 링크) 1.0.4 을 통해 호환 여전히 및 2.6.0 :

hdfs dfs -du [-s] [-h] URI [URI …]

hadoop fs -help더 많은 정보와 세부 사항을 위해 실행할 수도 있습니다 .


hadoop fs -du -s -h /path/to/dir 읽을 수있는 형식으로 디렉토리의 크기를 표시합니다.


Matt D 및 기타 답변으로 확장 하면 명령은 Apache Hadoop 3.0.0 까지 가능합니다.

hadoop fs -du [-s] [-h] [-v] [-x] URI [URI ...]

주어진 디렉토리에 포함 된 파일 및 디렉토리의 크기 또는 파일 인 경우 파일의 길이를 표시합니다.

옵션 :

  • -s 가 발생합니다 옵션 파일 길이의 집계 요약 아니라 개별 파일보다, 표시되는. -s 옵션이 없으면 주어진 경로에서 1 단계 깊이로 이동하여 계산이 수행됩니다.
  • -h 옵션은에서 파일 크기를 포맷합니다 사람이 읽을 수있는 방식 (예 : 64.0m 대신 67108864)
  • -v 옵션이 표시됩니다 열 이름을 헤더 라인으로.
  • -x 옵션을 사용합니다 스냅 샷 제외 결과 계산에서입니다. -x 옵션 (기본값)이 없으면 주어진 경로 아래의 모든 스냅 샷을 포함하여 항상 모든 INode에서 결과가 계산됩니다.

du는 다음 형식으로 세 개의 열을 반환합니다.

 +-------------------------------------------------------------------+ 
 | size  |  disk_space_consumed_with_all_replicas  |  full_path_name | 
 +-------------------------------------------------------------------+ 

예제 명령 :

hadoop fs -du /user/hadoop/dir1 \
    /user/hadoop/file1 \
    hdfs://nn.example.com/user/hadoop/dir1 

종료 코드 : 성공시 0을, 오류시 -1을 반환합니다.

출처 : Apache 문서


이것으로 당신은 GB 단위의 크기를 얻을 것입니다

hdfs dfs -du PATHTODIRECTORY | awk '/^[0-9]+/ { print int($1/(1024**3)) " [GB]\t" $2 }'

디렉토리 내의 특정 파일 그룹의 총계를 계산하려고 할 때 -s옵션이 작동하지 않습니다 (Hadoop 2.7.1에서). 예를 들면 :

디렉토리 구조 :

some_dir
├abc.txt    
├count1.txt 
├count2.txt 
└def.txt    

각 파일의 크기가 1KB라고 가정합니다. 다음을 사용하여 전체 디렉토리를 요약 할 수 있습니다.

hdfs dfs -du -s some_dir
4096 some_dir

그러나 "count"를 포함하는 모든 파일의 합계를 원하면 명령이 부족합니다.

hdfs dfs -du -s some_dir/count*
1024 some_dir/count1.txt
1024 some_dir/count2.txt

이 문제를 해결하기 위해 일반적으로 awk를 통해 출력을 전달합니다.

hdfs dfs -du some_dir/count* | awk '{ total+=$1 } END { print total }'
2048 

디렉토리의 크기를 얻으려면 hdfs dfs -du -s -h / $ yourDirectoryName을 사용할 수 있습니다. hdfs dfsadmin -report를 사용하여 빠른 클러스터 수준 저장소 보고서를 볼 수 있습니다.


Hadoop 클러스터에서 사용 된 공간의 %
sudo -u hdfs hadoop fs –df

특정 폴더의 용량 :
sudo -u hdfs hadoop fs -du -h /user


hadoop 버전 2.3.33 :

hadoop fs -dus  /path/to/dir  |   awk '{print $2/1024**3 " G"}' 

enter image description here


hdfs dfs -count <dir>

맨 페이지의 정보 :

-count [-q] [-h] [-v] [-t [<storage type>]] [-u] <path> ... :
  Count the number of directories, files and bytes under the paths
  that match the specified file pattern.  The output columns are:
  DIR_COUNT FILE_COUNT CONTENT_SIZE PATHNAME
  or, with the -q option:
  QUOTA REM_QUOTA SPACE_QUOTA REM_SPACE_QUOTA
        DIR_COUNT FILE_COUNT CONTENT_SIZE PATHNAME

명령은 hadoop fs -du -s -h \dirPath

  • -du [-s] [-h] ... : Show the amount of space, in bytes, used by the files that match the specified file pattern.

  • -s : Rather than showing the size of each individual file that matches the
    pattern, shows the total (summary) size.

  • -h : Formats the sizes of files in a human-readable fashion rather than a number of bytes. (Ex MB/GB/TB etc)

    Note that, even without the -s option, this only shows size summaries one level deep into a directory.

    The output is in the form size name(full path)

참고URL : https://stackoverflow.com/questions/6504107/the-way-to-check-a-hdfs-directorys-size

반응형