I have the following data in HDFS (2 files):
/a
/b
/c
/f1.txt
/f2.txt
I want to change permissions of f1.txt and f2.txt to 644: eg hadoop fs -chmod 644 /a/b/c/*.txt
However, in order to really grant access to those files I need to change the permissions of /b
and /c
to 755
: +x
to the directories containing the files. NOTE: I do not own /a
and that's already world readable.
Is there a hadoop fs
command that let's me do that? How about Java/Scala code?
You can use acls
for that :
To give a user read write and execute access
hdfs dfs -setfacl -m -R user:UserName:rwx /a/b/c/f1.txt
If you want to see the permissions on the file use getfacl
hdfs dfs -getfacl -R hdfs://somehost:8020/a/b/c/f1.txt
setfacl
Usage: hdfs dfs -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.
Examples:
hdfs dfs -setfacl -m user:hadoop:rw- /file
hdfs dfs -setfacl -x user:hadoop /file
hdfs dfs -setfacl -b /file
hdfs dfs -setfacl -k /dir
hdfs dfs -setfacl --set user::rw-,user:hadoop:rw-,group::r--,other::r-- /file
hdfs dfs -setfacl -R -m user:hadoop:r-x /dir
hdfs dfs -setfacl -m default:user:hadoop:r-x /dir
Exit Code:
Returns 0 on success and non-zero on error.
Use -R
(Recursive) option. It gives permission to all the files which present into directories.
hadoop fs -chmod -R 755 /a/b/c/
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.