1. chown
$ hadoop fs -help chown
-chown [-R] [OWNER][:[GROUP]] PATH... :
Changes owner and group of a file. This is similar to the shell's chown command
with a few exceptions.
-R modifies the files recursively. This is the only option currently
supported.
If only the owner or group is specified, then only the owner or group is
modified. The owner and group names may only consist of digits, alphabet, and
any of [-_./@a-zA-Z0-9]. The names are case sensitive.
WARNING: Avoid using '.' to separate user name and group though Linux allows it.
If user names have dots in them and you are using local file system, you might
see surprising results since the shell command 'chown' is used for local files.
与Linux 的chown命令类似,用来改变所属用户。只有微小的区别,应避免使用 . 来分隔用户和组。
hadoop fs -chown test /weiguo/caocao.txt
-R recursively递归地修改
hadoop fs -chown -R test:test /shuguo
2. chgrp
$ hadoop fs -help chgrp
-chgrp [-R] GROUP PATH... :
This is equivalent to -chown ... :GROUP ...
与Linux 的chgrp命令类似,用于改变文件的所属组。等同于 -chown ... :GROUP ... 。
hadoop fs -chgrp -R supergroup /shuguo
3. chmod
$ hadoop fs -help chmod
-chmod [-R] <MODE[,MODE]... | OCTALMODE> PATH... :
Changes permissions of a file. This works similar to the shell's chmod command
with a few exceptions.
-R modifies the files recursively. This is the only option currently
supported.
<MODE> Mode is the same as mode used for the shell's command. The only
letters recognized are 'rwxXt', e.g. +t,a+r,g-w,+rwx,o=r.
<OCTALMODE> Mode specifed in 3 or 4 digits. If 4 digits, the first may be 1 or
0 to turn the sticky bit on or off, respectively. Unlike the
shell command, it is not possible to specify only part of the
mode, e.g. 754 is same as u=rwx,g=rx,o=r.
If none of 'augo' is specified, 'a' is assumed and unlike the shell command, no
umask is applied.
和Linux的chmod命令类似,用来改变文件的读写执行权限。
hadoop fs -chmod -R 777 /shuguo
4. setfacl
$ hadoop fs -help setfacl
-setfacl [-R] [{-b|-k} {-m|-x <acl_spec>} <path>]|[--set <acl_spec> <path>] :
Sets Access Control Lists (ACLs) of files and directories.
Options:
-b Remove all but the base ACL entries. The entries for user, group
and others are retained for compatibility with permission bits.
-k Remove the default ACL.
-R Apply operations to all files and directories recursively.
-m Modify ACL. New entries are added to the ACL, and existing entries
are retained.
-x Remove specified ACL entries. Other ACL entries are retained.
--set Fully replace the ACL, discarding all existing entries. The
<acl_spec> must include entries for user, group, and others for
compatibility with permission bits.
<acl_spec> Comma separated list of ACL entries.
<path> File or directory to modify.
与Linux 的setfacl命令类似,用于设置文件或目录的访问控制列表。
我用的Hadoop3.1.3版本默认没有开启修改ACL的权限,但是官网的最新版Hadoop默认是开启的。如果没有开启,Hadoop会提示setfacl: The ACL operation has been rejected. Support for ACLs has been disabled by setting dfs.namenode.acls.enabled to false.
修改下hdfs-site.xml,然后再 重启 下HDFS就好,具体配置为下:
<property>
<name>dfs.namenode.acls.enabled</name>
<value>true</value>
</property>
-m 修改ACL
hadoop fs -setfacl -m user:hadoop:rw- /weiguo
-x 移除指定的ACL
hadoop fs -setfacl -x user:hadoop /weiguo
-b 移除所有ACL,最基础的除外。
hadoop fs -setfacl -b /weiguo
-k 移除默认的ACL。
hadoop fs -setfacl -k /weiguo
--set 完全替换ACL,丢弃所有已存在的项。
hadoop fs -setfacl --set user::rw-,user:hadoop:rw-,group::r--,other::r-- /weiguo
-R Recursively递归地设置ACL
hadoop fs -setfacl -R -m user:hadoop:r-x /shuguo
5. setfattr
$ hadoop fs -help setfattr
-setfattr {-n name [-v value] | -x name} <path> :
Sets an extended attribute name and value for a file or directory.
-n name The extended attribute name.
-v value The extended attribute value. There are three different encoding
methods for the value. If the argument is enclosed in double quotes,
then the value is the string inside the quotes. If the argument is
prefixed with 0x or 0X, then it is taken as a hexadecimal number. If
the argument begins with 0s or 0S, then it is taken as a base64
encoding.
-x name Remove the extended attribute.
<path> The file or directory.
设置文件或目录的拓展属性信息。在讲用getfattr查询时就已经提到过。
-n name 设置属性名
-v value 设置属性值
hadoop fs -setfattr -n user.myAttr -v myValue /shuguo
hadoop fs -setfattr -n user.noValue /shuguo
hadoop fs -getfattr -d /shuguo
|