gpt4 book ai didi

c - 我如何在 Linux 中授予对文件的写权限?

转载 作者:IT王子 更新时间:2023-10-29 00:21:29 25 4
gpt4 key购买 nike

我如何(以编程方式)在 Linux 中将文件的写入权限授予特定用户?比如,它的主人?每个人都对该文件具有读取权限。

最佳答案

在 shell 或 shell 脚本中只需使用:

chmod u+w <filename>

这只会修改用户的写入位,所有其他标志保持不变。

如果你想在 C 程序中这样做,你需要使用:

int chmod(const char *path, mode_t mode);

首先通过查询现有模式

int stat(const char *path, struct stat *buf);

... 然后通过执行 newMode = oldMode | 设置写入位S_IWUSR。有关详细信息,请参见 man 2 chmodman 2 stat

关于c - 我如何在 Linux 中授予对文件的写权限?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6732430/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com