HDFS SHELL 详解(6)

HDFS SHELL 总共有 39 条指令,本系列将逐步介绍每个指令的功能、选项含义及示例。
系列文章:
25.mv
执行方式:
功能描述:
在 HDFS 内部移动文件
选项解释:
示例:
把/hdfstest/mv_test.txt 移到/hdfstest2
hadoop fs -mv /hdfstest/mv_test.txt /hdfstest2

26.put
执行方式
功能描述:
将本地文件上传到 HDFS,与 copyFromLocal 一致
选项解释:
-f:若文件已存在,则覆盖文件
-p:保留源文件的创建时间、修改时间、所属用户及用户组
-l:允许 datanode 延迟保存文件副本到磁盘,让副本数保持为 1
-d:跳过创建._COPYING_的临时文件
示例:
拷贝本地文件 test.txt 到/hdfstest,并覆盖原文件
hadoop fs -put -f test.txt /hdfstest/test.txt

27.rm
执行方式:
功能描述:
删除文件或删除目录
选项解释:
-f:若文件不存在时,会跳过该文件,不会报错退出
-r|-R:递归指定目录下的所有文件夹/文件
-skipTrash:跳过回收站
-safely:使用该选项时,在删除目录的文件总数大于 hadoop.shell.delete.limit.num.files 之前,将提示安全确认。可以与-skipTrash 一起使用,以防止意外删除大目录
示例:
删除/hdfstest/rm_test.txt
hadoop fs -rm -f /hdfstet/rm_test.txt

递归删除/hdfstest2 目录
hadoop fs -rm -R -skipTrash -safely /hdfstest2

28.rmdir
执行方式:
功能描述:
删除空目录
选项解释:
--ignore-fail-on-non-empty:若目录不为空,则不会报错
示例:
删除/hdfstest2
hadoop fs -rmdir /hdfstest2

hadoop fs -rmdir --ignore-fail-on-non-empty /hdfstest2

删除/hdfstest2/rm_dir
hadoop fs -rmdir /hdfstest2/rm_dir

29.setfacl
执行方式:
功能描述:
设置对象或目录的 ACL(访问控制列表)
选项解释:
-b:剔除 user、group 及 other 外的 ACL
-k:剔除 default ACL
-m:添加新的 ACL 条目
-x:删除指定的 ACL 条目
--set:添加新的 ACL 条目并覆盖原有的 ACL 条目
-R:递归指定路径下的所有文件及文件夹
acl_spec:
ACL 条目,填写规范为<user/group/other>:<用户名/组别名>:<r/w/x/-(必须达到 3 位权限)>,比如 user:luorl:rw-,为 luorl 用户添加读写权限;group::rwx,为基本组别用户权限调整为读写执行。
示例:
为/hdfstest/test.txt 添加 luorl 用户读写权限
hadoop fs -setfacl -m user:luorl:rw- /hdfstest/test.txt

剔除上述添加的 luorl 用户权限
hadoop fs -setfacl -b /hdfstest/test.txt

为/hdfstest/添加 luorl 用户读写权限,并设置为 defalut ACL
hadoop fs -setfacl -m default:user:luorl:rw- /hdfstest

设置目录的 defalut ACL 后,后续在该目录下新建的文件夹/文件都会带上 default ACL

剔除上述添加的 luorl 用户的 defalut ACL
hadoop fs -setfacl -k /hdfstest

为/hdfstest/test.txt 设置 user::rwx,user:luorl:rw,group::rw-,other::r—权限,并覆盖原有权限
重新设置/hdfstest/test.txt 文件的权限

hadoop fs -setfacl --set user::rwx,user:luorl:rw-,group::rw-,other::r-- /hdfstest/test.txt

可见文件权限已被完全覆盖
版权声明: 本文为 InfoQ 作者【罗小龙】的原创文章。
原文链接:【http://xie.infoq.cn/article/04270934272b2edea58ef0191】。文章转载请联系作者。
评论