https://stackoverflow.com/questions/36553701/how-to-set-permissions-recursively-700-for-folders-and-600-for-files-without-u

I'm trying to figure out a way to set permissions recursively 700 for dirs and subdirs on a specific path and 600 for files. I would use these commands:

find /path -type d -print0 | xargs -0 chmod 700

find /path -type f -print0 | xargs -0 chmod 600

But the user does not have permission to run the "find" command. As a workaround I tried to make a script that contains the above commands from the root user with setuid sticky bit set so it will run with root privileges (like passwd or sudo commands that normal users run with root privileges):

chmod 4755 script.sh

but i cannot execute the script from the limited user account, it still says that I don't have permission to run the find command.

Does anyone have any idea how i can accomplish this without having to use the "find" command?

Edit: OS: Centos 6.5

Apparently this is very easy to implement. There are 2 ways: using chmod only, or setting ACL (access control list) on the desired path:

Using chmod i would run:

chmod -R u=rwX,g=,o= /path

for the user owner i'm giving capital "X", so it does apply only to directories and not files.

Using ACL:

setfacl -Rm u::rwX,g::0,o::0 /path

setfacl -Rm d:u::rwX,g::0,o::0 /path

again using capital "X" so it applies only to directories and not files. The first command applies the ACL, the second one makes it default policy so newly created files will inherit the desired permissions.

不用find,怎样递归地给目录设置700,给文件设置600权限?的更多相关文章

  1. Python3:递归实现输出目录下所有的文件

    今天来整理一下os库中方法的使用,如何输出一个目录下的所有文件? 1.首先介绍几个基本的的方法: 1)os.getcwd()  #返回当前工作目录 2)os.listdir()    #返回一个列表, ...

  2. Linux递归解压缩一个目录下的全部文件

    gunzip -r hongchangfirst/data 怎样递归删除那些剩余的非log结尾的文件? 先列出确认一下: find hongchangfirst/data -type f ! -nam ...

  3. Linux更改目录及其子目录、文件的访问权限

    修改某个目录及其下所有文件的权限,要使用-R参数,表示启动递归处理. 例如: #仅将/home/user/test目录的权限设置为rwxr-xr-x /home/user/test #表示将整个/ho ...

  4. svnkit递归获取指定目录下的全部文件

    package demo.wc; import java.util.Collection; import java.util.Iterator; import org.tmatesoft.svn.co ...

  5. go递归打印指定目录下的所有文件及文件夹

    func treedir(fpath string){ // 获取fileinfo if finfo,err := os.Stat(fpath); err == nil { // 判断是不是目录 如果 ...

  6. java 递归获取一个目录下的所有文件路径

    还是日志的问题,log4j生成的日志文件,自动保存到月份所在的文件夹中,需要获取到所有的日志文件,包括文件夹 private List<String> ergodic(File file, ...

  7. 递归删除指定目录下的 .git 文件

    转载自:http://my.oschina.net/armsky/blog/34447 find . -name .git | xargs rm -fr 其中对 xargs 的介绍,可以参照以下内容: ...

  8. 给定HDFS中某一个目录,输出该目录下的所有文件的读写权限、大小、创建时间、路径等信息,如果该文件是目录,则递归输出该目录下所有文件相关信息。

    1 import java.text.SimpleDateFormat; 2 import org.apache.hadoop.fs.*; 3 4 public class E_RecursiveRe ...

  9. Apache限制某个目录下的PHP文件没有执行权限

    为了安全期间,有时我们需要限制网站下的某些目录对于php脚本不能执行. 有两种方法可以参考: 1.  使用.htaccess 文件限制 在要限制php执行的目录下,创建.htaccess文件,加入内容 ...

  10. wamp中的httpd.conf文件设置

    ServerName localhost 缺省情况下,并不需要指定这个ServerName参数,服务器将自动通过名字解析过程来获得自己的名字,但如果服务器的名字解析有问题(通常为反向解析不正确),或者 ...

随机推荐

  1. 【C/C++】two pointers/归并排序/原理/理解/实现/算法笔记4.6

    1.two pointers 思路:对序列进行扫描的时候,根据序列本身的特性用两个下标i和j对序列进行扫描,从而降低算法复杂度. ·例1 在递增序列中找a + b = M while (i<j) ...

  2. 【简】题解 AWSL090429 【原子】

    预处理出每个原子最近的不能合并的位置 枚举当前位置和前面断开的位置合并 发现还是不能过 考虑用选段树优化 但是因为每次转移的最优点是在前面可以合并的范围内 dp值加上当前的到该点的最大值 因为每个位置 ...

  3. 关于导入Eclips Web项目报错的解决方案

    1.是一定要有耐心,耐心,耐心,重要的事情说三遍.针对问题一 一破解,一步一步来,不要放弃. 2.其实百度就好了他们有报错的各种问题及解决方案 ,包括导入项目web.xml报错,js文件,jsp文件报 ...

  4. 如何查看Python中所有关键字

    一.保留字即关键字,我们不能把它们用作任何标识符名称.Python的标准库提供了一个keyword模块,可以输出当前版本的所有关键字 import keyword print(keyword.kwli ...

  5. docker初识-docker安装、基于docker安装mysql及tomcat、基本命令

    一.docker是什么 用go语言开发,开源的应用容器引擎,容器性能开销极低 二.整体架构图 Docker 包括三个基本概念: 镜像(Image):Docker 镜像(Image),就相当于是一个 r ...

  6. Uni-app原生插件入门使用教程-[1]从Uni-app插件市场试用插件

    [1]从Uniapp插件市场试用插件 当HBuilderX中提供的能力无法满足App功能需求,需要通过使用Andorid/iOS原生开发实现时,可使用App离线SDK开发原生插件来扩展原生能力. 如使 ...

  7. 什么是SEO配置

    SEO是什么 搜索引擎优化,又称为SEO,即Search Engine Optimization,它是一种通过分析搜索引擎的排名规律,了解各种搜索引擎怎样进行搜索.怎样抓取互联网页面.怎样确定特定关键 ...

  8. SpringBoot整合redis实现过期key监听事件

    Spring整合redis实现key过期事件监听:https://www.cnblogs.com/pxblog/p/13969375.html 可以用于简单的过期订单取消支付.7天自动收货场景中 1. ...

  9. c++11之 algorithm 算法库新增 minmax_element同时计算最大值和最小值

    0.时刻提醒自己 Note: vector的释放 1. minmax_element 功能 寻找范围 [first, last) 中最小和最大的元素. 2. 头文件 #include <algo ...

  10. 使用.NET 6开发TodoList应用(8)——实现全局异常处理

    系列导航 使用.NET 6开发TodoList应用文章索引 需求 因为在项目中,会有各种各样的领域异常或系统异常被抛出来,那么在Controller里就需要进行完整的try-catch捕获,并根据是否 ...