四喜三顺

海量数据挖掘·高性能计算·数据分析与预测

首页 新随笔 联系 订阅 管理
 
文件操作权限:
chmod 三个八进制数字 文件名
其中:三个八进制数字,第一个代表本用户的权限,第二个代表同组的权限,第三个代表其他用户的权限
4代表可读
2代表可写
1代表可执行
例如:chmod 754 file1.c 代表file1.c文件对本用户可读可写可执行,对同组用户可读可执行,对其他用户可读。

创建目录:
int mkdir(char *pathname, mode_t mode);
示例:
 1 int main()
 2 {
 3     char *path="/root/tmp11";
 4     if(mkdir(path, 0754)==0) /*权限设置参数,第一个0代表八进制数,754含义同上;如果创建成功,返回0*/
 5     {   
 6         printf("created the directory %s. \n", path);
 7     }
 8     else
 9     {
10         printf("error\n");
11     }
12     return 0;
13 }

删除目录函数:
int rmdir(char *pathname);
删除非空目录及目录中的所有文件:
rm -rf pathname
 
创建文件函数:
int creat(char *pathname, mode_t mode);/*成功时返回创建文件的句柄,否则返回-1*/

删除文件函数:
int remove(char *pathname);

文件锁定函数:
防止多个用户同时访问一个文件,出现数据不一致的情况
int flock(int fd, int operation); /*文件锁定成功时返回0,否则返回-1*/
其中,operation可以是:
LOCK_SH:共享锁,其他程序可以同时访问这个文件
LOCK_EX:互斥锁,其他用户不能同时访问这个文件
LOCK_UN:解除文件锁定状态
LOCK_NB:无法建立锁定时,马上返回进程,通常与LOCK_SH或LOCK_EX做OR(|)组合。


posted on 2014-03-24 15:45  四喜三顺  阅读(134)  评论(0编辑  收藏  举报