Search

HDFS CLI

CLI를 이용해 HDFS에 접근하기 위해 다음과 같은 접두어를 사용할 수 있다.
> hadoop fs
Bash
복사
> hdfs dfs
Bash
복사
1.
디렉토리 생성
> hadoop fs -mkdir /user/malachai > hadoop fs -mkdir /user/malachai/input
Bash
복사
2.
디렉토리 내 조회
> hadoop fs -ls /user/malachai Found 1 items drwxr-xr-x - root supergroup 0 2022-11-29 05:50 /user/malachai/input
Bash
복사
3.
로컬 파일을 HDFS로 복사
> hadoop fs -put LICENSE.txt /user/malachai/input > hadoop fs -ls /user/malachai/input Found 1 items -rw-r--r-- 1 root supergroup 15217 2022-11-29 05:55 /user/malachai/input/LICENSE.txt
Bash
복사
> hadoop fs -copyFromLocal LICENSE.txt /user/malachai/input > hadoop fs -ls /user/malachai/input Found 1 items -rw-r--r-- 1 root supergroup 15217 2022-11-29 05:55 /user/malachai/input/LICENSE.txt
Bash
복사
4.
HDFS 내 파일dmf 로컬에 복사
> hadoop fs -get LICENSE.txt /user/malachai/input/LICENSE.txt ./
Bash
복사
> hadoop fs -copyToLocal LICENSE.txt /user/malachai/input/LICENSE.txt ./
Bash
복사
5.
HDFS 내 파일 내용 출력
> hadoop fs -cat /user/malachai/input/LICENSE.txt ... asio-1.10.2 (hadoop-hdfs-project/hadoop-hdfs-native-client/src/main/native/libhdfspp/third_party/asio-1.10.2) rapidxml-1.13 (hadoop-hdfs-project/hadoop-hdfs-native-client/src/main/native/libhdfspp/third_party/rapidxml-1.13) tr2 (hadoop-hdfs-project/hadoop-hdfs-native-client/src/main/native/libhdfspp/third_party/tr2) Public Domain ------------- hadoop-hdfs-project/hadoop-hdfs/src/main/webapps/static/json-bignum.js
Bash
복사
> hadoop fs -tail /user/malachai/input/LICENSE.txt ... asio-1.10.2 (hadoop-hdfs-project/hadoop-hdfs-native-client/src/main/native/libhdfspp/third_party/asio-1.10.2) rapidxml-1.13 (hadoop-hdfs-project/hadoop-hdfs-native-client/src/main/native/libhdfspp/third_party/rapidxml-1.13) tr2 (hadoop-hdfs-project/hadoop-hdfs-native-client/src/main/native/libhdfspp/third_party/tr2) Public Domain ------------- hadoop-hdfs-project/hadoop-hdfs/src/main/webapps/static/json-bignum.js
Bash
복사
> hadoop fs -head /user/malachai/input/LICENSE.txt Apache License Version 2.0, January 2004 http://www.apache.org/licenses/ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 1. Definitions. ...
Bash
복사
6.
HDFS 내 파일 이동
> hadoop fs -mv /user/malachai/input/LICENSE.txt /user/malachai/LICENSE.txt
Bash
복사
6.
HDFS 내 파일 복사
> hadoop fs -cp /user/malachai/input/LICENSE.txt /user/malachai/LICENSE.txt
Bash
복사
6.
HDFS 내 파일 삭제
> hadoop fs -rm /user/malachai/LICENSE.txt Deleted /user/malachai/LICENSE.txt
Bash
복사