HDFS SHELL 详解(7)

HDFS SHELL 总共有 39 条指令,本系列将逐步介绍每个指令的功能、选项含义及示例。
系列文章:
30.setfattr
执行方式:
功能描述:
设置对象或目录的扩展属性
选项解释:
-n:设置扩展属性的名称
-v:设置扩展属性的值,必须搭配-n 使用
-x:移除扩展属性
示例:
为/hdfstest/test.txt 新增扩展属性 user.MyAttr
hadoop fs -setfattr -n user.MyAttr /hdfstest/test.txt

为/hdfstest/test.txt 扩展属性 user.MyAttr 设置值 MyValue
hadoop fs -setfattr -n user.MyAttr -v MyValue /hdfstest/test.txt

为/hdfstest/test.txt 移除扩展属性 user.MyAttr

31.getfattr
执行方式:
功能描述:
显示目录或对象的扩展属性名和值
选项解释:
-R:递归指定路径下的所有文件及文件夹
-n:按指定的扩展属性名称展示
-d:显示所有扩展属性
-e:按指定编码展示扩展属性的值,必须搭配-n name 或-d 使用。编码类型分为 text(文本)、hex(16 进制)、base64(64 位加密)。
示例:
展示/hdfstest/test.txt 的 user.MyAttr 扩展属性
hadoop fs -getfattr -n user.MyAttr /hdfstest/test.txt

展示/hdfstest/test.txt 所有扩展属性
hadoop fs -getfattr -d /hdfstest/test.txt

展示/hdfstest/test.txt 的 user.MyAttr 扩展属性,并属性值进行 64 位加密
hadoop fs -getfattr -n user.MyAttr -e base64 /hdfstest/test.txt

32.setrep
执行方式:
功能描述:
更改指定对象的复制副本数,若指定对象为目录,将迭代更改目录下的所有对象
选项解释:
-R:为了向后兼容而设计,暂时无效果
-w:等待副本复制完成才结束命令
rep:设置副本数
示例:
将/hdfstest/test.txt 设置为 2 副本
hadoop fs -setrep -w 2 /hdfstest/test.txt

33.stat
执行方式:
功能描述:
根据格式显示指定对象的信息
选项解释:
format 规范:
type:
显示对象的类型。参数为 %F
若对象属于文件,则显示为 regular file
若对象属于目录,则显示为 directory
permissions:
显示对象的权限设置。
%a 显示为八进制权限,比如 644
%A 显示为 ACL 条目,比如 rw-r--r--
bytes:
显示对象大小,单位为字节。参数为 %b
user name of owner:
显示对象所属用户名称。参数为 %u
group name of owner:
显示对象所属组别名称。参数为 %g
name:
显示对象名称。参数为 %n
block size:
显示对象所在的数据块大小,一般为 HDFS 设置的数据块大小。若对象为目录,则显示大小为 0。参数为 %o
replication:
显示对象的复制副本数。参数为 %r
access date:
显示对象的创建时间。
参数为 %x 时,显示为"yyyy-MM-dd HH:mm:ss"
参数为 %X 时,显示为从“1970-1-1”到创建时间的秒数
modification date:
显示对象的修改时间。
参数为 %y 时,显示为"yyyy-MM-dd HH:mm:ss"
参数为 %Y 时,显示为从“1970-1-1”到修改时间的秒数
示例:
按格式显示/hdfstest/test.txt 的类型、八进制权限、所属用户及组别、副本数、创建时间、修改时间
hadoop fs -stat "Type:%F Perm:%a %u:%g Rep:%r Accestime:%x Modifytime:%y" /hdfstest/test.txt

34.tail
执行方式:
功能描述:
显示文件最后 1kb 的内容
选项解释:
-f:持续输出文件内容
示例:
输出/hdfstest/test.txt 最后 1kb 的内容
hadoop fs -tail /hdfstest/test.txt

版权声明: 本文为 InfoQ 作者【罗小龙】的原创文章。
原文链接:【http://xie.infoq.cn/article/d1de6d305242a8ec3e9425cec】。文章转载请联系作者。
评论