hadoop shell 命令总结
Usage: hadoop fs [generic options]
[-appendToFile … ]
[-cat [-ignoreCrc] …]
[-checksum …]
[-chgrp [-R] GROUP PATH…]
[-chmod [-R] <MODE[,MODE]… | OCTALMODE> PATH…]
[-chown [-R] [OWNER][:[GROUP]] PATH…]
[-copyFromLocal [-f] [-p] [-l] … ]
[-copyToLocal [-p] [-ignoreCrc] [-crc] … ]
[-count [-q] [-h]
[-cp [-f] [-p | -p[topax]] … ]
[-createSnapshot []]
[-deleteSnapshot ]
[-df [-h] [
[-du [-s] [-h]
[-expunge]
[-find
[-get [-p] [-ignoreCrc] [-crc] … ]
[-getfacl [-R]
[-getfattr [-R] {-n name | -d} [-e en]
[-getmerge [-nl] ]
[-help [cmd …]]
[-ls [-d] [-h] [-R] [
[-mkdir [-p]
[-moveFromLocal … ]
[-moveToLocal ]
[-mv … ]
[-put [-f] [-p] [-l] … ]
[-renameSnapshot ]
[-rm [-f] [-r|-R] [-skipTrash] …]
[-rmdir [–ignore-fail-on-non-empty]
[-setfacl [-R] [{-b|-k} {-m|-x <acl_spec>}
[-setfattr {-n name [-v value] | -x name}
[-setrep [-R] [-w]
[-stat [format]
[-tail [-f] ]
[-test -[defsz]
[-text [-ignoreCrc] …]
[-touchz
[-truncate [-w]
[-usage [cmd …]]
ls
-ls [-d] [-h] [-R] [
…]
说明:
列出与指定文件模式匹配的内容
示例:
hadoop fs -ls /
参数:
参数 | 原文 | 说明 |
---|---|---|
-d | Directories are listed as plain files. | 目录作为普通文件列出。 |
-h | Formats the sizes of files in a human-readable fashion rather than a number of bytes. | 将文件大小格式化为人类可读的方式,而不是字节数。 |
-r | Recursively list the contents of directories. | 递归地列出目录的内容。 |
mkdir
-mkdir [-p]
…
说明:
在指定位置创建目录
示例:
hadoop fs -mkdir /test
参数:
参数 | 原文 | 说明 |
---|---|---|
-p | Do not fail if the directory already exists | 如果目录已经存在,则不会失败 |
moveFromLocal
-moveFromLocal … :
说明:
从本地剪切粘贴到HDFS。与-put相同,不同之处在于源文件在复制后会被删除。
示例:
hadoop fs -moveFromLocal <本地路径文件> <hdfs上传路径>
appendToFile
-appendToFile …
说明:
追加一个文件到已经存在的文件末尾
示例:
hadoop fs -appendToFile <本地路径> <hdfs追加文件的路径>
cat
-cat [-ignoreCrc] …
说明:
显示文件内容
示例:
hadoop fs -cat /test/a.txt
copyFromLocal
-copyFromLocal [-f] [-p] [-l] … :
说明:
从本地文件系统中拷贝文件到HDFS路径去。与-put命令相同
示例:
hadoop fs -copyFromLocal <本地文件> <hdfs路径地址>
参数:
参数 | 原文 | 说明 |
---|---|---|
-f | Overwrites the destination if it already exists. | 如果目标已经存在,则覆盖该目标。 |
-p | Preserves access and modification times, ownership and the mode. | 保留访问和修改时间、所有权和模式。 |
-l | Allow DataNode to lazily persist the file to disk. Forces replication factor of 1. This flag will result in reduced durability. Use with care. | 允许DataNode将文件延迟保存到磁盘。强制复制因子为1。此标志将导致耐久性降低。小心使用。 |
copyToLocal
-copyToLocal [-p] [-ignoreCrc] [-crc] … :
说明:
从HDFS拷贝到本地
示例:
hadoop fs -copyToLocal /sanguo/shuguo/kongming.txt ./
cp
-cp [-f] [-p | -p[topax]] … :
说明:
从HDFS的一个路径拷贝到HDFS的另一个路径
示例:
hadoop fs -cp /sanguo/shuguo/kongming.txt /zhuge.txt
mv
-mv … :
说明:
在HDFS目录中移动文件
示例:
hadoop fs -mv /zhuge.txt /sanguo/shuguo/
get
-get [-p] [-ignoreCrc] [-crc] … :
说明:
从HDFS下载文件到本地。等同于copyToLocal
示例:
hadoop fs -get /sanguo/shuguo/kongming.txt ./
getmerge
-getmerge [-nl] :
说明:
合并下载多个文件,比如HDFS的目录 /test下有多个文件:log.1, log.2,log.3,...
示例:
hadoop fs -getmerge /test/* ./zaiyiqi.txt
参数:
参数 | 原文 | 说明 |
---|---|---|
-nl | Add a newline character at the end of each file. | 在每个文件的末尾添加换行符。 |
put
-put [-f] [-p] [-l] … :
说明:
从本地文件系统中拷贝文件到HDFS路径去。与-copyFromLocal命令相同
示例:
hadoop fs -put ./zaiyiqi.txt /test/
参数:
参数 | 原文 | 说明 |
---|---|---|
-f | Overwrites the destination if it already exists. | 如果目标已经存在,则覆盖该目标。 |
-p | Preserves access and modification times, ownership and the mode. | 保留访问和修改时间、所有权和模式。 |
-l | Allow DataNode to lazily persist the file to disk. Forces replication factor of 1. This flag will result in reduced durability. Use with care. | 允许DataNode将文件延迟保存到磁盘。强制复制因子为1。此标志将导致耐久性降低。小心使用。 |
tail
-tail [-f] :
说明:
显示一个文件的末尾 显示文件的最后1KB。
示例:
hadoop fs -tail /test/a.txt
参数:
参数 | 原文 | 说明 |
---|---|---|
-f | Shows appended data as the file grows. | 随着文件的增长显示追加的数据。 |
rm
-rm [-f] [-r|-R] [-skipTrash] … :
说明:
删除所有符合指定文件模式的文件
示例:
hadoop fs -rm /test/jinlian2.txt
参数:
参数 | 原文 | 说明 |
---|---|---|
-skipTrash | option bypasses trash, if enabled, and immediately deletes | 选项绕过垃圾处理,如果启用,并立即删除 |
-f | If the file does not exist, do not display a diagnostic message or modify the exit status to reflect an error. | 如果该文件不存在,则不显示诊断消息或修改退出状态以反映错误。 |
- r | Recursively deletes directories | 递归删除目录 |
rmdir
-rmdir [–ignore-fail-on-non-empty]
… :
说明:
删除空目录
示例:
hadoop fs -mkdir /test
du
-du [-s] [-h]
… :
说明:
统计文件夹的大小信息
示例:
hadoop fs -du -s -h /test
参数:
参数 | 原文 | 说明 |
---|---|---|
-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. | 将文件大小格式化为人类可读的方式,而不是字节数。 |
setrep
-setrep [-R] [-w]
… :
说明:
设置HDFS中文件的副本数量
示例:
hadoop fs -setrep 10 /test/kongming.txt
参数:
参数 | 原文 | 说明 |
---|---|---|
-W | It requests that the command waits for the replication to complete. This can potentially take a very long time. | 它请求命令等待复制完成。这可能需要很长时间。 |
-R | It is accepted for backwards compatibility. It has no effect | 向后兼容是可以接受的。没有效果 |