Dar*_*ust 25
在shell或shell脚本中,只需使用:
chmod u+w <filename>
Run Code Online (Sandbox Code Playgroud)
这仅修改用户的写入位,所有其他标志保持不变.
如果要在C程序中执行此操作,则需要使用:
int chmod(const char *path, mode_t mode);
Run Code Online (Sandbox Code Playgroud)
首先通过查询现有模式
int stat(const char *path, struct stat *buf);
Run Code Online (Sandbox Code Playgroud)
...然后只需设置写入位newMode = oldMode | S_IWUSR.查看man 2 chmod并man 2 stat了解详情.
八进制模式644将为所有者提供读写权限,并且只读取组的其余部分以及其他用户的权限.
read = 4
write = 2
execute = 1
owner = read | write = 6
group = read = 4
other = read = 4
Run Code Online (Sandbox Code Playgroud)
设置模式的命令的基本语法是
chmod 644 [file name]
Run Code Online (Sandbox Code Playgroud)
在C中,那将是
#include <sys/stat.h>
chmod("[file name]", 0644);
Run Code Online (Sandbox Code Playgroud)