HDFS—shell command

Introduction to common command parameters:

-help: output this command parameter manual

[hadoop@hadoop02 ~]$ hadoop -help
[hadoop@hadoop02 ~]$ hadoop fs -help
[hadoop@hadoop02 ~]$ hadoop fs -help ls

-ls: Display directory information

hadoop fs -ls hdfs://hadoop02:9000/

Note: In these parameters, all hdfs paths can be abbreviated as hadoop fs -ls / equivalent to the effect of the previous command

-mkdir: create a directory on hdfs

hadoop fs -mkdir -p /aa/bb/cc/dd

-put: equivalent to copyFromLocal, for file upload

hadoop fs -put /aaa/jdk.tar.gz /bbb/jdk.tar.gz.2

-get: equivalent to copyToLocal, which is to download files from hdfs to local

hadoop fs -get /aaa/jdk.tar.gz

-getmerge: merge and download multiple files
Example: There are multiple files under the directory /aaa/ of getmerge hdfs: log.1, log.2,log.3,...

hadoop fs -getmerge /aaa/log.* ./log.sum

-cp: Copy another path of hdfs from one path of hdfs

hadoop fs -cp /aaa/jdk.tar.gz /bbb/jdk.tar.gz.2

-mv: move files in the hdfs directory

hadoop fs -mv /aaa/jdk.tar.gz /

-rm: delete files or folders

hadoop fs -rm -r /aaa/bbb/

-rmdir: delete empty directories

hadoop fs -rmdir /aaa/bbb/ccc

-moveFromLocal: cut from local to hdfs

hadoop fs - moveFromLocal /home/hadoop/a.txt /aa/bb/cc/dd

-moveToLocal: cut from hdfs to local

hadoop fs - moveToLocal /aa/bb/cc/dd /home/hadoop/a.txt

-copyFromLocal: copy files from the local file system to the hdfs file system

hadoop fs -copyFromLocal ./jdk.tar.gz /aaa/

-copyToLocal: copy from hdfs to local

hadoop fs -copyToLocal /aaa/jdk.tar.gz

-appendToFile: Append a file to the end of an existing file

hadoop fs -appendToFile ./hello.txt hdfs://hadoop-server01:9000/hello.txt
# 可以简写为:
hadoop fs -appendToFile ./hello.txt /hello.txt

-cat: display file content

hadoop fs -cat /hello.txt

-tail: display the end of a file

hadoop fs -tail /weblog/access_log.1

-text: Print the content of a file in character form

hadoop fs -text /weblog/access_log.1

-chgrp, -chmod, -chown: The usage in the linux file system is the same, and the file ownership permissions

hadoop fs -chmod 666 /hello.txt
hadoop fs -chown someuser:somegrp /hello.txt

-df: Count the available space information of the file system

hadoop fs -df -h /

-du: Statistics about the size of the folder

hadoop fs -du -s -h /aaa/*

-count: count the number of file nodes in a specified directory

hadoop fs -count /aaa/

-setrep: Set the number of copies of files in hdfs
 

hadoop fs -setrep 3 /aaa/jdk.tar.gz

Supplement: The command to view the working status of the dfs cluster

hdfs dfsadmin -report

 

Guess you like

Origin blog.csdn.net/sanmi8276/article/details/113064480