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 -p /user/data 

-moveFromLocal从本地剪切粘贴到hdfs

  hadoop fs -moveFromLocal /opt/test/xx.zip  /user/data

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

  touch note.txt
  vi note.txt
  hadoop fs -appendToFile note.txt  /user/wcinput/wc.input

-cat :显示文件内容

  hadoop fs -cat  /user/wcinput/wc.input

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

  hadoop fs -tail /user/wcinput/wc.input

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

   hadoop  fs  -chmod  777   /user/wcinput/wc.input
   hadoop fs -chown root:root   /user/wcinput/wc.input

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

  cd  /opt/test
  rz xiaowangzi.txt
  hadoop fs -copyFromLocal /opt/test/xiaowangzi.txt   /user/input/
  hadoop fs -copyFromLocal /opt/test/xiaowangzi.txt   /user/input/小王子.txt

-copyToLocal:从hdfs拷贝到本地

  cd /opt
  mkdir download
  hadoop fs -copyToLocal /user/input/小王子.txt /opt/download/tonghua.txt  

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

  hadoop fs -cp /user/input/xiaowangzi.txt  /xiaowangzi.txt   #拷贝到根路径

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

   hadoop fs -mkdir -p /user/output
   hadoop fs -mv /xiaowangzi.txt   /user/output/

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

  cd /opt
  mkdir download
  hadoop fs -get /user/input/xiaowangzi.txt     /opt/download/

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

  hadoop fs -getmerge /user/input/*  /all.txt

-put:等同于copyFromLocal

  cd /opt
  cd test

  hadoop fs -put test.txt /user/input/test/

-rm:删除文件或文件夹

  hadoop fs -rm -r -f  /user/input/xiaowangzi.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  /kong.txt

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

  hadoop fs -count  /user/

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

  hadoop fs -setrep 2 /user/input/xiaowangzi.txt

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

  hadoop fsck  /user/input/xiaowangzi.txt -files -blocks -locations  -racks 
原文地址:https://www.cnblogs.com/asksk/p/12340837.html