使所有新目录具有777权限 [英] Make all new directories have 777 permissions

查看:67
本文介绍了使所有新目录具有777权限的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个脚本,该脚本在运行时会在/home/test/中创建一个目录,然后在其中写入一些文件.当我运行此脚本时,它可以正常工作.但是,当我使用perp脚本使用

I have a script that, when run, creates a directory inside /home/test/ and then writes some files in it. When I run this script, it works fine. However, when I call it from a perl script with

$ret = `/home/..../testscript.py`

它没有权限,因此它无法创建文件夹,或者在创建之后无法在其中写入.看起来当Python执行open("/home/test/abcde/file1.txt", "w")时,该文件具有权限-rw-r--r--

it doesn't have permissions so it can't create the folder, or can't write inside it after it is created. It looks like when Python does open("/home/test/abcde/file1.txt", "w"), that file has permissions -rw-r--r--

该如何解决?有没有一种方法可以设置/home/test递归地使所有子目录具有全局写访问权限?还是更好的解决方案?

What can I do to get around this? Is there a way to set /home/test to recursively make all subdirectories have global write-access? Or a better solution maybe?

推荐答案

输入:

os.umask(0000)

在创建目录之前,使用Python脚本中的

.如果您无法更改Python脚本,请输入:

in the Python script before it creates the directory. If you can't change the Python script, put:

umask(0000)

在Perl脚本中调用Python脚本之前.

in the Perl script before it calls the Python script.

创建新文件或目录时,通过获取对creat()mkdir()的调用中指定的权限,然后掩盖umask中指定的位,来确定权限.

When a new file or directory is created, the permissions are determined by taking the permissions specified in the call to creat() or mkdir(), and then masking off the bits that are specified in the umask.

通常,应用程序在调用函数时指定06660777权限(取决于它们是否正在创建应可执行的内容). umask的通用值是022,它会关闭组和世界写权限.如果您不希望它们被关闭,请使用上面的umask值来保留呼叫中指定的权限.

Typically, applications specify 0666 or 0777 permissions when they call the function (depending on whether they're creating something that should be executable or not). A common value for umask is 022, which turns off group and world write permissions. If you don't want them turned off, use the above umask value to keep the permissions specified in the call.

这篇关于使所有新目录具有777权限的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆