chmod、fchmod

头文件

#include <sys/stat.h>

函数原型

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

功能

chmod函数在指定的文件上进行操作,改变现有文件的访问权限。fchmod对已打开的文件进行操作。修改时,进程的有效用户ID必须等于文件的所有者ID,或是root运行的此进程。

参数

mode常量
       S_ISUID  (04000)  set-user-ID  (set  process  effective  user  ID   onexecve(2))//执行时设置用户IDS_ISGID  (02000)  set-group-ID  (set  process  effective  group  ID onexecve(2);  mandatory  locking,  as   described   infcntl(2); take a new file's group from parent direc-tory, as described in chown(2) and mkdir(2))//执行时设置组IDS_ISVTX  (01000)  sticky bit (restricted deletion flag,  as  describedin unlink(2))//保存正文(粘住位)S_IRUSR  (00400)  read by owner//用户(所有者)读S_IWUSR  (00200)  write by owner//用户(所有者)写S_IXUSR  (00100)  execute/search by owner ("search" applies for direc-tories, and means that entries within the  directorycan be accessed)//用户(所有者)执行S_IRGRP  (00040)  read by group//组读S_IWGRP  (00020)  write by group//组写S_IXGRP  (00010)  execute/search by group//组执行S_IROTH  (00004)  read by others//其他读S_IWOTH  (00002)  write by others//其他写S_IXOTH  (00001)  execute/search by others//其他执行S_IRWXU  (UNIX)   //用户读写执行S_IRWXG  (UNIX)   //组读写执行S_IRWXO  (UNIX)   //其他读写执行

unix环境高级编程的例子

#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/stat.h>int main(int argc, char * argv[])
{struct stat statbuf;if(stat("foo", &statbuf) <  0){printf("stat error for foo\n");} if(chmod("foo", (statbuf.st_mode & ~S_IXGRP) | S_ISGID) < 0){printf("chmod error for foo\n");}if(chmod("bar", S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH) < 0){printf("chmod error for bar\n");}exit(0);
}

Linux chmod、fchmod函数相关推荐

  1. linux chmod和fchmod设置 文件和目录权限设置

    这两个函数使我们可以更改现有文件的访问权限: #include <sys/stat.h> int chmod( const char *pathname, mode_t mode ); i ...

  2. linux文件操作函数程序,linux 文件操作函数

    文件操作(Linux) 常用linux函数库中的基本函数 1. close函数,关闭文件 2. creat函数,建立文件 3. dup.dup2函数,复制文件描述词 4. fcntl函数,文件描述词操 ...

  3. Linux 常用C函数说明-文件权限控制篇

    chdir(改变当前的工作(目录) 相关函数  getcwd,chroot 表头文件  #include<unistd.h> 定义函数  int chdir(const char * pa ...

  4. linux常用c函数(中文版)

    都是linux的c函数东西略多,用页面搜索来查找吧. << Back to man.ChinaUnix.net isalnum(测试字符是否为英文或数字) 相关函数 isalpha,isd ...

  5. unix环境高级编程-4.9-chmod,fchmod函数和粘住位

    这两个函数可以更改我们现有文件的访问权限. #include <sys/stat.h>int chmod(const char *pathname,mode_t mode);int fch ...

  6. Linux下select函数实现的聊天服务器

    转载: http://blog.csdn.net/microtong/article/details/4989902 Linux下select函数实现的聊天服务器  佟强 http://blog.cs ...

  7. 嵌入式linux通过程序设置系统时间,嵌入式新手如何设定Linux的时间函数

    一.时间相关说明 格林威治时间表示0时区的标准时间.其他时区的时间和此标准时间均有时间差.UTC(UniversalTime Coordinated)是世界协调时间,是格林威治时间在互联网中的表示方法 ...

  8. Linux chmod命令修改文件与文件夹权限命令代码

    在Linux中要修改一个文件夹或文件的权限我们需要用到linux chmod命令来做,下面我写了几个简单的实例大家可参考一下. 语法如下: chmod [who] [+ | - | =] [mode] ...

  9. linux c数字转字符串函数,Linux常用C函数—字符串转换篇

    Linux 常用C 函数-字符串转换篇 atof (将字符串转换成浮点型数) 相关函数 atoi ,atol ,strtod ,strtol ,strtoul 定义函数 double atof(con ...

  10. linux下syscall函数,SYS_gettid,SYS_tgkill

    出处:http://blog.chinaunix.net/uid-28458801-id-4630215.html linux下syscall函数,SYS_gettid,SYS_tgkill 2014 ...

最新文章

  1. Docker入门六部曲——容器
  2. Microsoft Hyper-V Server 2012开启虚拟化-虚拟机管理
  3. linux系统中文件编程,Linux当中的文件系统
  4. echarts图形报表缓存问题(option数据缓存)
  5. 《大道至简》第六章读后感
  6. Java opengl openal_项目里用到了openal,特分享一下openal全教程
  7. iptables 防火墙的基本使用
  8. php excel下载打不开了,php下载excel无法打开的解决方法
  9. adcetris研发历程_AZ、MSD、吉利德争相布局ADC药物
  10. 野火IMJAVA开发的即时通讯系统源码
  11. uva11054 - Wine trading in Gergovia(等价转换,贪心法)
  12. Your CPU supports instructions that this TensorFlow binary was not compiled to use: AVX2问题解决
  13. Python爬取图片时,urllib提示没有属性urlretrieve的问题
  14. java中的值传递与引用传递
  15. visio防火墙可以连接什么_分享一款网工必备网络拓扑图绘制工具Visio以及大量厂商图标库...
  16. JS设计模式 - 工厂模式
  17. *jqwidgets jqxgrid 使用心得 jqxgrid教程 jqxgrid+SpringMVC(初级) 集成JAVA SSM
  18. 我敲,原来滚动监听可以酱紫写
  19. 工欲善其事,必先利其器 - 修炼Android Studio操作技巧
  20. 一款Img图床模板码 扩展性超强纯Html+响应式

热门文章

  1. 好用的局域网共享工具有哪些?win10系统如何设置?
  2. NetSpeedMonitor:在任务栏中监视网络下载、上传情况
  3. 强行进入远程计算机,远程桌面强制连接命令
  4. C# web 读取excel并导入数据库
  5. Android SDK下载安装及配置教程
  6. 计算机2017语言排名,2017计算机编程语言排行榜 java依然独占鳌头
  7. java全局校验拦截器
  8. AMPL实现中国邮递员问题,你get到了吗
  9. 软件项目管理 project 实验
  10. 史上最全的vim快捷键