- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
如果文件不存在,我的 python 脚本会创建一个文件,然后读取和写入该文件。该脚本可以由 root(自动)或由用户(刷新请求)运行。我需要创建具有写入权限的文件,以便在这两种情况下都可以重写文件。
import os
f = os.open('file', os.O_CREAT, 0777)
os.close(f)
但是……
$ ls -l
-rwxr-xr-x 1 pi pi 0 Feb 22 13:51 file
但是,这个脚本有效,我不明白其中的区别:
import os
f = os.open('file', os.O_CREAT)
os.fchmod(f, 0777)
os.close(f)
...然后:
$ ls -l
-rwxrwxrwx 1 pi pi 0 Feb 22 13:54 file
最佳答案
您不是在设置 umask
,您是在设置文件模式位,它们被 umask
屏蔽。 Per the documentation :
Open the file file and set various flags according to flags and possibly its mode according to mode. The default mode is 0777 (octal), and the current umask value is first masked out. ...
您的 umask
值似乎是 0022
,因此屏蔽了组和其他用户的写入权限。
这个
os.fchmod(f, 0777)
尽管有 umask
值,但明确将文件权限设置为 0777
。
关于Python os.open() 无法将 umask 设置为 777(最大 755),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35564749/
在大多数地方,权限被定义为格式为0777 的八进制数。但是 UNIX 的 umask 命令(因此 os.umask())需要 0o000 来生成 0o777 的权限位,并且0o022 在我的理解中等于
经过一些挖掘和帮助后 from other people ,我发现我在 git 中的 umask 设置有问题。我想要实现的是在我的服务器上 check out 的任何 git repo,umask 设
如何通过 ssh 引导在远程机器上启动的进程使用某个 umask 运行?我希望这也适用于作为标准 Capistrano 配方的一部分运行的命令,所以我不能只对命令的“umask”部分进行显式调用。 似
我正在编写一个函数来将 D 应用程序转换为守护程序。我打算分享它(虽然我不知道在哪里。有什么地方吗,所以也许它会进入火卫一。无论如何) 一切都很好。我正在使用 core.sys.posix.unist
在处理可执行文件或目录的权限时,我了解 umask 的工作原理,至少是基本的工作原理。但是,当谈到 umask 如何将其规则应用于文本文件时,我感到很纠结。 例如,考虑 umask 037。在新创建的
我是 ionic 框架的新手。今天我尝试使用 ionic 创建一个新项目。当我尝试使用此命令 ionic platform add android 将 android 平台添加到我的应用程序时,出现以
在 Ubuntu Linux 中,更改系统的 umask(例如通过在程序中调用 umask())是否会影响系统上消息队列等 IPC 设施的创建和使用? 最佳答案 来自 the man page The
我正在阅读一些源代码,我在主例程的最开始发现了这条语句: umask(077); 这可能是什么原因? 手册页 (man 2 umask) 指出: umask -- set file creation
umask(0); fd = open("/dev/null", O_RDWR); 这是man 2 umask: umask() sets the calling process’s file mod
我有一项服务是 Python REST API。此服务在内部使用执行一些脚本, subprocess.Popen(cmd, shell=False, preexec_fn=os.setpgrp, en
我对 Git 有疑问。我在 Google 和 StackOverflow 中搜索了解决方案,但没有任何帮助。 问题是每次 git 更新工作目录中的某些文件时(当我 checkout 分支或 merge
如何检查当前正在运行的程序的 umask? [更新:另一个进程,不是当前进程。] 最佳答案 您可以将 gdb 附加到正在运行的进程,然后在调试器中调用 umask: (gdb) attach ...
我在 Centos 6 上有一个由 jsvc 托管的应用程序。随之创建了许多日志。我的问题是 jsvc 正在创建具有 077 权限的日志,除了 root 之外任何人都无法访问这些日志。任何人都应该可以
我有一个 umask 0002 使用 umask -S 它返回 u=rwx,g=rwx,o=rx. 我如何找到现在根据掩码设置权限的所有文件和目录? 目录为 777 - mask 和文件为 666 -
我有一个名为 MAIN_OUTPUT 的目录。我有一个 JAVA 应用程序,它将在 MAIN_OUTPUT 下创建一些文件和目录。提交 java 应用程序的用户始终不同。现在的要求是将这个特定目录(M
我有一个写入日志文件的程序。当然必须创建这个日志文件和文件夹,我的程序必须以 root 身份运行,所以它总是创建具有 rw-------- 权限的文件夹,并且不能以普通用户身份读取和写入。我不希望这样
我注意到,如果您中断 rsync,一些新目录仍然具有权限 drwx------,尽管当前的 umask 是 0022. 我启动了 gdb 并试图在调用 mkdir() 之前显式调用 umask(0),
具体来说,我需要给文件 rw----r--和目录 rwx--xr-x 最佳答案 使用 umask 062。 这是有效的,因为 umask 仅取消设置位,并且通常不会在创建文件时首先设置可执行位: $
umask 似乎在各种文件(centos)中设置为: /etc/profile /etc/profile.d/umask.sh /etc/login.defs ... 这个的优先顺序是什么? 此外,当
在 Django 应用程序中,我创建了一个临时文件。此临时文件是使用“0700”权限创建的。但是,我需要在不保留临时文件(0700)权限的情况下重命名该临时文件,但希望该文件获得用户(umask)的权
我是一名优秀的程序员,十分优秀!