Issue
I have the following directories on the HDFS(which loosely follows the POSIX model) :
[ojoqcu@sandbox ~]$ hdfs dfs -ls /
Found 11 items
drwxrwxrwx - yarn hadoop 0 2016-03-14 14:19 /app-logs
drwxr-xr-x - hdfs hdfs 0 2016-06-27 09:40 /apps
drwxr-xr-x - yarn hadoop 0 2016-03-14 14:19 /ats
drwxr-xr-x - hdfs hdfs 0 2016-03-14 14:50 /demo
drwxr-xr-x - hdfs hdfs 0 2016-03-14 14:19 /hdp
drwxr-xr-x - mapred hdfs 0 2016-03-14 14:19 /mapred
drwxrwxrwx - mapred hadoop 0 2016-03-14 14:19 /mr-history
drwxr-xr-x - hdfs hdfs 0 2016-03-14 14:42 /ranger
drwxrwxrwx - spark hadoop 0 2016-06-27 10:02 /spark-history
drwxrwxrwx - hdfs hdfs 0 2016-06-27 09:38 /tmp
drwxr-xr-x - hdfs hdfs 0 2016-06-27 09:38 /user
As obvious, the 'others' can freely operate on these directories.
I wish to keep the owner and group permissions unchanged/as-is but change the 'others' to custom form e.g
drwxr-xr-x - hdfs hdfs 0 2016-06-27 09:40 /apps
to
drwxr-x--- - hdfs hdfs 0 2016-06-27 09:40 /apps
drwxr-xr-x - hdfs hdfs 0 2016-03-14 14:19 /hdp
to
drwxr-xr-- - hdfs hdfs 0 2016-03-14 14:19 /hdp
In extreme case, I may need to provide only read or no access at all to the other users e.g :
drwxrwxr-- - yarn hadoop 0 2016-03-14 14:19 /app-logs
drwxr-xr-- - hdfs hdfs 0 2016-06-27 09:40 /apps
drwxr-xr-- - yarn hadoop 0 2016-03-14 14:19 /ats
drwxr-xr-- - hdfs hdfs 0 2016-03-14 14:50 /demo
drwxr-xr-- - hdfs hdfs 0 2016-03-14 14:19 /hdp
drwxr-xr-- - mapred hdfs 0 2016-03-14 14:19 /mapred
drwxrwxr-- - mapred hadoop 0 2016-03-14 14:19 /mr-history
drwxr-xr-- - hdfs hdfs 0 2016-03-14 14:42 /ranger
drwxrwxr-- - spark hadoop 0 2016-06-27 10:02 /spark-history
drwxrwxr-- - hdfs hdfs 0 2016-06-27 09:38 /tmp
drwxr-xr-- - hdfs hdfs 0 2016-06-27 09:38 /user
How can I recursively do this without specifying the bits for owner and group ?
Solution
Taken from here: https://www.washington.edu/computing/unix/permissions.html
To change the mode of a file, use the chmod command. The general form is
chmod X@Y file1 file2 ...
where: X is any combination of the letters 'u' (for owner), 'g' (for group), 'o' (for others), 'a' (for all; that is, for `ugo'); @ is either '+' to add permissions, '-' to remove permissions, or '=' to assign permissions absolutely; and Y is any combination of 'r', 'w', 'x'. Following are some examples:
chmod u=rx file (Give the owner rx permissions, not w) chmod go-rwx file (Deny rwx permission for group, others) chmod g+w file (Give write permission to the group) chmod a+x file1 file2 (Give execute permission to everybody) chmod g+rx,o+x file (OK to combine like this with a comma)
so according this, answer will be:
chmod -R o-wx path
Answered By - num8er