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. spring boot @EnableWebMvc禁用springMvc自动配置原理。

    说明: 在spring boot中如果定义了自己的java配置文件,并且在文件上使用了@EnableWebMvc 注解,那么sprig boot 的默认配置就会失效.如默认的静态文件配置路径:&quo ...

  2. spring整合mybatis和springmvc的配置概图

  3. inndy_rop

    又学习到了一个新知识 拿到题目例行检查,发现是32位的程序,放入ida中 进入main看到了一个overflow函数进入查看 存在明显的栈溢出,看到题目知道要用rop来做,但是完全没有思路, 后来发现 ...

  4. [BUUCTF]PWN——inndy_rop

    inndy_rop 附件 步骤: 例行检查,32位,开启了nx保护 本地调试运行没看出个啥,直接上ida,一开始f5会报错, 找到报错提示的位置,点击option–>general调出如图的界面 ...

  5. 教会你彻底解决android studio c/c++ jni代码无法跳转

    时不时总会遇到原来c c++ jni代码跳转很欢乐,突然也不知道咋滴了build也能build成功,运行也能正常运行,就是代码不能跳转了,首先来科普下一些背景知识. 如果让代码跳转起来,大概需要做哪些 ...

  6. LuoguB2013 温度表达转化 题解

    Content 输入华氏温度 \(F\),请将其转化为摄氏温度 \(C\),精确到小数点后 \(5\) 位. 数据范围:\(F\geqslant -459.67\). Solution 简单的输入输出 ...

  7. SpringBoot基础篇(一)

    1.前言 什么是SpringBoot:springboot是当下一套流行的J2EE框架.借助微服务的思想.将业务分成一个个的服务.通过spring-cloud进行整合.最后通过spring-data进 ...

  8. centos7安装docker,并配置镜像加速

    yum安装gcc yum -y install gcc yum -y install gcc-c++ 卸载旧版本 (没有可忽略) yum -y remove docker docker-common ...

  9. Linux(Centos)内存占用过高处理

    查看内存占用最大 ps aux| grep -v "USER" |sort -n -r -k 4 |awk 'NR==1{ print $0}' 命令查看占用内存最大的10个进程 ...

  10. nanogui之更新子模块glfw3.3.2踩坑总结

    nanogui源码下载: A . https://github.com/wjakob/nanogui B . https://github.com/dalerank/nanogui B是fork的A, ...