2016-06-27 78 views
0

我對HDFS以下目錄(這大致符合POSIX模式):更改權限只有

[[email protected] ~]$ 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-信息,但改變「其他」自定義形式,例如

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 

在極端的情況下,我可能只需要提供讀取或無法訪問所有其他用戶,例如:

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 

我怎樣才能遞歸做到這一點,而無需指定所有者和組的位?

回答

1

從這裏摘自:https://www.washington.edu/computing/unix/permissions.html

要更改文件的模式,使用chmod命令。一般形式是

chmod [email protected] file1 file2 ... 

其中:X是字母的任意組合 'U'(所有者), 'G'(對於 組), 'O'(對於其他), 'A'(對於所有;也就是說,'ugo'); @爲 要麼添加權限,要麼刪除權限,要麼刪除權限,要麼授予'='至 絕對地賦予權限; Y是'r','w', 'x'的任意組合。下面是一些例子:

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) 

所以根據這一點,答案將是:

chmod -R o-wx path 
+1

@fedorqui感謝編輯 – num8er

+1

沒問題:)我覺得這是必要的,以提高可讀性 – fedorqui