hadoop支持命令行操作HDFS文件系统,并且支持shell-like命令与HDFS文件系统交互,对于大多数程序猿/媛来说,shell-like命令行操作都是比较熟悉的,其实这也是Hadoop的极大便利之一,至少对于想熟悉乃至尽快熟练操作HDFS的人来说。

由于平时在工作中经常用到Hadoop Shell命令来操作HDFS上的文件,有时候因为Hadoop Shell命令不熟悉,需要重新查找;或者需要某个命令的参数;再或者需要知晓相似命令的差异;于是便有了本文,对于Hadoop Shell命令的总结,方便自己以后得工作,也算是对类似工作的总结。

hadoop fs FsShell
Usage: java FsShell
[-ls <path>]
[-lsr <path>]
[-df [<path>]]
[-du <path>]
[-dus <path>]
[-count[-q] <path>]
[-mv <src> <dst>]
[-cp <src> <dst>]
[-rm [-skipTrash] <path>]
[-rmr [-skipTrash] <path>]
[-expunge]
[-put <localsrc> ... <dst>]
[-copyFromLocal <localsrc> ... <dst>]
[-moveFromLocal <localsrc> ... <dst>]
[-get [-ignoreCrc] [-crc] <src> <localdst>]
[-getmerge <src> <localdst> [addnl]]
[-cat <src>]
[-text <src>]
[-copyToLocal [-ignoreCrc] [-crc] <src> <localdst>]
[-moveToLocal [-crc] <src> <localdst>]
[-mkdir <path>]
[-setrep [-R] [-w] <rep> <path/file>]
[-touchz <path>]
[-test -[ezd] <path>]
[-stat [format] <path>]
[-snapshot <path>]
[-tail [-f] <file>]
[-chmod [-R] <MODE[,MODE]... | OCTALMODE> PATH...]
[-chown [-R] [OWNER][:[GROUP]] PATH...]
[-chgrp [-R] GROUP PATH...]
[-help [cmd]]

下面详细解释一下命令的操作,这些命令和Unix下的命令差不多,有些看了就明白其含义了。

hadoop fs -ls <path>

返回文件path的统计信息,信息包括:
permissions number_of_replicas userid groupid filesize modification_date modification_time filename

hadoop fs -lsr <path>

这个是ls的recursive版本,类似于ls -R命令和ls的区别。

hadoop fs -du URI

显示文件的大小。

hadoop fs -dus URI

类似于du -s:显示文件及其子目录的总体大小。

hadoop fs -df <path>

显示Hadoop所使用的文件系统的大小。

hadoop fs -count [-q] <path>

显示path 下的目录数量,文件大小等信息。默认情况下显示一下信息:
DIR_COUNT, FILE_COUNT, CONTENT_SIZE FILE_NAME

添加-q信息后,输出的信息更多:

QUOTA, REMAINING_QUATA, SPACE_QUOTA, REMAINING_SPACE_QUOTA, DIR_COUNT, FILE_COUNT, CONTENT_SIZE, FILE_NAME

hadoop fs -mv <src> <dst>

从src移动到dst,允许多个源移动到同一个dst,dst必须是目录。

hadoop fs -cp <src> ... <dst>

拷贝多个源到dst,限制是dst必须是目录。

hadoop fs -rm [-skipTrash] <path>

删除文件,不能删除目录
-skipTrash:直接删除文件,不再往.Trash里面放。

hadoop fs -rmr [-skipTrash] <path>

这个能够迭代删除目录及其下面的文件
-skipTrash:直接删除文件,不再往.Trash里面放。

hadoop fs -expunge

清空Trash,Trash的概念详见http://hadoop.apache.org/docs/r1.0.4/hdfs_design.html,参考下Trash的含义

When a file is deleted by a user or an application, it is not immediately removed from HDFS. Instead, HDFS first renames it to a file in the /trash directory. The file can be restored quickly as long as it remains in /trash. A file remains in /trash for a configurable amount of time. After the expiry of its life in /trash, the NameNode deletes the file from the HDFS namespace. The deletion of a file causes the blocks associated with the file to be freed. Note that there could be an appreciable time delay between the time a file is deleted by a user and the time of the corresponding increase in free space in HDFS.

A user can Undelete a file after deleting it as long as it remains in the /trash directory. If a user wants to undelete a file that he/she has deleted, he/she can navigate the /trash directory and retrieve the file. The /trash directory contains only the latest copy of the file that was deleted. The /trash directory is just like any other directory with one special feature: HDFS applies specified policies to automatically delete files from this directory. The current default policy is to delete files from /trash that are more than 6 hours old. In the future, this policy will be configurable through a well defined interface.

文件传输:

hadoop fs -put <localsrc> ... <dst>

复制单个、或者多个本地FS的目录或者文件到目标文件系统。

hadoop fs -copyFromLocal <localsrc> ... <dst>

和put命令类似,唯一的限制是src必须是本地的文件。

hadoop fs -moveFromLocal <localsrc> ... <dst>

和put命令类似,这个命令会在localsrc执行完成后,删除本地的文件,注意是删除本地的文件。

hadoop fs -get [-ignoreCrc] <localsrc> ... <dst>

拷贝FS上的src到本地的dst目录
-ignoreCrc:拷贝时忽略crc检验,如果想拷贝CRCs,需要添加-crc参数。

hadoop fs -getmerge <src> <localdst> [addnl]

src是源目录,localdst是本地目标文件,将源目录的所有文件连接成本地目标文件。addnl是可选的,用于指定在每个文件结尾添加一个换行符。

hadoop fs -cat <src>

将src的内容输出到stdout,和Unix下面的cat功能类似。

hadoop fs -text <src>

把src文件按照text输出,zip或者TextRecordInputStream格式的也可以按照text输出。

hadoop fs -copyToLocal [-ignoreCrc] [-crc] <src> <localdst>

和get命令类似,唯一的限制是dst必须是本地文件系统的文件。

hadoop fs -moveToLocal [-crc] <src> <localdst>

输出:'-moveToLocal' is not implemented yet,还没有实现。

hadoop fs -mkdir <path>

创建path文件夹,如果path的父目录不存在,会迭代创建,类似于mkdir -p命令。

hadoop fs -setrep [-R] <rep> <path/file>

修改HDFS文件或者目录的Replication数目,对于重要的文件,需要增加副本数目,确保不会丢失或者损坏。
-R参数表示迭代更新,目录下面的副本数目同时更新。

hadoop fs -touchz <path>

创建一个大小为0的文件。

hadoop fs -test -[ezd] <path>

测试文件的目录属性,-e:测试文件是否存在;-z:文件大小是否为0;-d:测试是否是目录。

hadoop fs -stat [format] <path>

返回目录的统计信息。

hadoop fs -tail [-f] <file>

显示文件的最后1kb信息,-f参数和Unix下面的参数一样。

hadoop fs -chmod [-R] <MODE[,MODE]... | OCTALMODE> PATH...
hadoop fs -chown [-R] [OWNER][:[GROUP]] PATH...
hadoop fs -chgrp [-R] GROUP PATH...

这三个是权限操作命令,和Unix命令下的功能类似。

Hadoop Shell命令还是比较简单的,只是其中的差别必须等到用的时候才能体会,本文只是做个备忘,将工作中常用的命令整理下。

转自:http://isilic.iteye.com/blog/1770036

Hadoop Shell命令大全的更多相关文章

  1. redis shell命令大全

    redis shell命令大全(转自http://blog.mkfree.com/posts/5105432f975ad0eb7d135964) 作者:oyhk   2013-1-28 3:11:35 ...

  2. Windows常用shell命令大全

    Windows常用shell命令大全 基于鼠标操作的后果就是OS界面外观发生改变, 就得多花学习成本.更主要的是基于界面引导Path与命令行直达速度是难以比拟的.另外Geek很大一部分是键盘控,而非鼠 ...

  3. Windows常用shell命令大全(转)

    [Windows常用shell命令大全] 基于鼠标操作的后果就是OS界面外观发生改变, 就得多花学习成本.更主要的是基于界面引导Path与命令行直达速度是难以比拟的.另外Geek很大一部分是键盘控,而 ...

  4. tasker支持的shell 命令大全

    参考 http://www.notenoughtech.com/tasker/tasker-run-shell-commands/   罗列所有系统配置项 settings list system s ...

  5. Hadoop Shell命令字典(可收藏)

    可以带着下面问题来阅读: 1.chmod与chown的区别是什麽?2.cat将路径指定文件的内容输出到哪里?3.cp能否是不同之间复制?4.hdfs如何查看文件大小?5.hdfs如何合并文件?6.如何 ...

  6. Android系统在超级终端下必会的命令大全(adb shell命令大全)

    . 显示系统中全部Android平台: android list targets . 显示系统中全部AVD(模拟器): android list avd . 创建AVD(模拟器): android c ...

  7. Hadoop Shell命令(基于linux操作系统上传下载文件到hdfs文件系统基本命令学习)

    Apache-->hadoop的官网文档命令学习:http://hadoop.apache.org/docs/r1.0.4/cn/hdfs_shell.html FS Shell 调用文件系统( ...

  8. Hadoop shell命令

    1.FS Shell 调用文件系统(FS)shell命令应使用bin/hadoop fs <args>的形式.所有的的FS shell命令使用URI路径作为参数.URI格式是scheme: ...

  9. hadoop Shell命令详解

    调用文件系统(FS)Shell命令应使用bin/hadoop fs <args>的形式.所有的的FS shell命令使用URI路径作为参数.URI路径详解点击这里. 1.cat说明:将路径 ...

随机推荐

  1. C语言 · 判定数字

    编写函数,判断某个给定字符是否为数字. 样例输入 9 样例输出 yes #include<stdio.h> int main(){ char c; scanf("%c" ...

  2. SQL Server-聚焦NOT IN VS NOT EXISTS VS LEFT JOIN...IS NULL性能分析(十八)

    前言 本节我们来综合比较NOT IN VS NOT EXISTS VS LEFT JOIN...IS NULL的性能,简短的内容,深入的理解,Always to review the basics. ...

  3. python通过protobuf实现rpc

    由于项目组现在用的rpc是基于google protobuf rpc协议实现的,所以花了点时间了解下protobuf rpc.rpc对于做分布式系统的人来说肯定不陌生,对于rpc不了解的童鞋可以自行g ...

  4. openresty 前端开发入门四之Redis篇

    这章主要演示怎么通过lua连接redis,并根据用户输入的key从redis获取value,并返回给用户 操作redis主要用到了lua-resty-redis库,代码可以在github上找得到 而且 ...

  5. BPM配置故事之案例1-配置简单流程

    某天,Boss找到了信息部工程师小明. Boss:咱们新上了H3 BPM,你研究研究把现在的采购申请流程加上去吧,这是采购申请单. 小明:好嘞 采购申请单 小明回去后拿着表单想了想,开始着手配置. 他 ...

  6. Dynamics CRM 之ADFS 使用 WID 的独立联合服务器

    ADFS 的使用 WID 的独立联合服务器适用于自己的测试环境,常用的就是在虚机中使用. 拓扑图如下: wID:联合身份验证服务配置为使用 Windows 内部数据库

  7. SQL字符串函数

    LEN() :计算字符串长度(字符的个数.)datalength();//计算字符串所占用的字节数,不属于字符串函数.测试varchar变量与nvarchar变量存储字符串a的区别.见备注1.LOWE ...

  8. Android快乐贪吃蛇游戏实战项目开发教程-06虚拟方向键(五)绘制方向键箭头

    本系列教程概述与目录:http://www.cnblogs.com/chengyujia/p/5787111.html本系列教程项目源码GitHub地址:https://github.com/jack ...

  9. BZOJ 1692: [Usaco2007 Dec]队列变换 [后缀数组 贪心]

    1692: [Usaco2007 Dec]队列变换 Time Limit: 5 Sec  Memory Limit: 64 MBSubmit: 1383  Solved: 582[Submit][St ...

  10. SpringMVC初步

    SpringMVC框架介绍 1) Spring MVC属于SpringFrameWork的后续产品,已经融合在Spring Web Flow里面. Spring 框架提供了构建 Web 应用程序的全功 ...