首页 > 代码库 > 特殊文件的操作-Linux C

特殊文件的操作-Linux C

1.

目录文件

在Linux下目录也是用文件来描述的特殊文件

 

创建文件夹

#include<sys/types.h>#include<sys/stat.h>int mkdir(const char *pathname,mode_t mode);

删除文件夹(目录必须是空目录)

#include<unistd.h>int rmdir(const char *pathname);

 

#include<sys/types.h>#include<dirent.h>//打开目录DIR *opendir(const char *pathname);//关闭目录int closedir(DIR *dp);//读取目录文件struct dirent *readdir(DIR *dp);
#include<unistd.h>//更改目录int chdir(const char *pathname);int fchdir(int fd);//获取目录名char *getcwd(char *buf,size_t size);

 

2.

链接文件的操作

硬链接:

#include<unistd.h>//硬链接要求链接文件和源文件必须在同一文件系统中int link(const char *pathname1,const char *pathname2);//删除链接int unlink(const char *pathname);#include<stdio.h>//解除链接int remove(const char *pathname);

 

符号链接;

#include<unistd.h>//创建符号链接int symlink(const char *actualpath,const char *sympath);//打开链接并获取链接名字int readlink(const char *pathname,char *buf,int bufsize);

 

3.

管道文件:

#include<stdio.h>int pipe(int filedes[2]);

通常用于进程间通信

特殊文件的操作-Linux C