unix 环境高级编程4 - 文件和目录

一、获取文件和目录的信息

#include 
#include 
int stat(const char *pathname, struct stat * buf) ;
int fstat(int fd,struct stat * buf) ;
int lstat(const char *pathname, struct stat * buf) ;

二、文件类型

#include 
#include 
#include 
using namespace std;

int main(int argc, char* argv[])
{
    int i;
    struct stat buf;
    char* ptr;
    for(i=1; i

三、许可权测试

#include 
//mode:R_OK 可读, W_OK 可写, X_OK 可执行, F_OK 文件是否存在
int access(const char *pathname, int mode ) ;

四、修改存取权限

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

五、更改文件的用户ID和组ID

#include 
#include 
int chown(const char *path, uid_t owner, gid_t group) ;
int fchown(int  fd, uid_t owner, gid_t group) ;
int lchown(const char * path, uid_t owner, gid_t group) ;

六、文件截断

#include 
#include 
int truncate(const char *path, off_t length) ;
int ftruncate(int fd, off_t length) ;

七、符号连接

符号连接时对一个文件的间接指针

八、文件时间

st_atime 文件数据的最后存取时间read -u
st_mtime 文件数据的最后修改时间 write 缺省
st_ctime i节点状态的最后更改时间 chmod, chown - c
#include 
#include 
int utime(const char* path, const struct utimbuf* time )




->剩余9995小时30分钟

你可能感兴趣的:(10000小时计划)