1.改变文件的访问权限chmod(p98)
- 命令行中:chmod (u/g/o/a)(+/-/=)(r/w/x/s) 文件名
- u+s:表明其他用户有和root一样的权限。
- o+t:表明除root和所有者,其他人都不能删除此文件。
- 以可以用数字代替权限:chmod 644 文件名。
- 更改目录权限时,加 -R 同时更改目录下文件的权限。
#include<sys/types.h>
#include<stat.h>
int chmod(const char *path , mode_t mode);
int fchmod(int fp , mode_t mode);
2.改变文件的访问时间和修改时间
#include<stdio.h>
#include<utime.h>
int utime(const char *filename , struct utimbiuf*buf);
struct utimbuf{
time_t actime; 访问时间
time_t modtime; 修改时间
};
3.改变文件的所有者和所属组
- 在命令行中:chown 所有者 文件名
- 或chown 所有者:所属组 文件名
- 更改所属组:chgrp 所属组 文件名
- 更改目录权限时,加 -R 同时更改目录下文件的权限
#include<sys/types.h>
#include<unistd.h>
int chown("filename",new_owner,new_group);
int fchown(int fp,new_owner,new_group);
int lchown("filename",new_owner,new_group); 修改软链接本身文件的属性
4.修改文件长度
头文件同chown
int truncate("filename",length);
int ftruncate(int fp,length);
延长的部分用0补