hadoop常用的操作指令

-help:查看帮助

hadoop fs -help rm
-rm [-f] [-r|-R] [-skipTrash] <src> ... :
  Delete all files that match the specified file pattern. Equivalent to the Unix
  command "rm <src>"
                                                                                 
  -skipTrash  option bypasses trash, if enabled, and immediately deletes <src>   
  -f          If the file does not exist, do not display a diagnostic message or 
              modify the exit status to reflect an error.                        
  -[rR]       Recursively deletes directories

-ls: 显示目录信息(此处是已经创建过的目录)

hadoop fs -ls /

-lsr: 递归显示文件信息

hadoop fs  -lsr  /

-mkdir:在hdfs上创建目录

hadoop fs -mkdir /HDP01

-moveFromLocal从本地剪切粘贴到hdfs 

hadoop fs -moveFromLocal /opt/other/jdk-8u221-linux-x64.tar.gz /HDP01

--appendToFile :追加一个文件到已经存在的文件末尾

touch n.txt
vi n.txt
hadoop fs -appendToFile n.txt  /HDP01/note.txt

-cat :显示文件内容

hadoop fs -cat  /HDP01/note.txt

-tail:显示一个文件的末尾

hadoop fs -tail  /HDP01/note.txt

-chgrp 、-chmod、-chown:linux文件系统中的用法一样,修改文件所属权限

hadoop  fs  -chmod  777  /HDP01/note.txt
 hadoop fs -chown root:hadoop104  /HDP01/note.txt

-copyFromLocal:从本地文件系统中拷贝文件到hdfs路径去

cd  /opt/other
touch note.txt
hadoop fs -copyFromLocal  /opt/other/note.txt   /HDP01

-copyToLocal:从hdfs拷贝到本地

cd /opt/other
hadoop fs -copyToLocal /HDP01/note.txt  /opt/other 

-cp :从hdfs的一个路径拷贝到hdfs的另一个路径

hadoop fs -cp /HDP01/note.txt  /  #拷贝到根路径

-mv:在hdfs目录中移动文件

 hadoop fs -mv /note.txt   /UPLOAD

-get:等同于copyToLocal,就是从hdfs下载文件到本地

hadoop fs -get /UPLOAD/note.txt     /opt/other

-getmerge :合并下载多个文件,比如hdfs的目录 /HDP01下有多个文件1.txt,2.txt

hadoop fs -getmerge /HDP01/*  all.txt

-put:等同于copyFromLocal

hadoop fs -put  /opt/other/note.txt  /HDP01

-rm:删除文件或文件夹

hadoop fs -rm -r -f  /HDP01/1.txt

-rmdir:删除空目录

hadoop fs -mkdir /test
hadoop fs -mkdir /test

-df :统计文件系统的可用空间信息

hadoop fs -df -h  /

-du统计文件夹的大小信息

hadoop fs -du -s -h /user

-touthz: 创建一个空文件

hadoop fs -touchz  /1.txt

-count: 查看某路径下文件的数量

hadoop fs -count  /UPLOAD

-setrep:设置hdfs中文件的副本数量

hadoop fs -setrep 2 /HDP01/hello.txt

fsck:查看某个文件的详细信息

hadoop fsck  /HDP01/hello.txt -files -blocks -locations  -racks 

 

原文地址:https://www.cnblogs.com/yangy1/p/12341101.html