Linux 文件 操作
2017-01-21 22:46
363 查看
Linux file 操作
目录结构体struct dirent{ ino_t ... } struct dirent
inode
proc inode 不一样
目录遍历
off_t posreaddir // 读取目录信息
打印目录树
打开目录 readdir 判断文件是否为目录d_type==4 考虑. ..recursive 递归
#include<sys/types.h> #include<dirent.h> #include<stido.h> void printdir(char *path,int width) // 打印路径下的文件,width控制格式 { DIR* dir; // define dir dir=opendir(path); // open dir if(NULL==dir) // dir true or false { perror("opendir"); return; } struct dirent *p; // 目录结构 char buf[200]={0}; while( (p=readdir(dir))!=NULL ) //考虑当前目录,不然死循环 { if((strcmp(p->d_name,".")||strcmp(p->d_name,"..")){ // continue }else{ printf("%*s%s\n",width,"",p->d_name); //按层及目录打印 // p->d_name; if(p->d_type==4) // 4 { sprintf(buf,"%s%s%s",path,"/",p->d_name); // 拼接 printdir(buf,width+4); } } } } // int main(int argc,char *argv[]) {if(argc!=2){ printf("error args!!!,check your args"); return -1 ; } printf("%s\n",argv[1]); printdir(argv[1],0); return 0; } < 不错,今天调整的变为平静,空间、世界、love、do、change
软链接:存的是路径
硬连接:iNode 入口
// ls -l unistd.h stdio.h ... int ret=0; int main() { if(argc!=2){ printf("error"); } } struct stat buf; // use struct stat memset(&buf,0,sizeof(buf)); // iniciaze ret=stat(argv[1],&buf); if // ret ==-1 // for dir printf("mode=%d" // buf.st_mode ... // getpwuid()
type 文件类型是单独存储的
getpwuid
think how to 81b4 to -rw-rw-r– ls -l
for(){ // number to char function }
标准输入、输出
基于描述
创建文件main
// 创建
// open(const *path, int flags,mode_t mode)
open(argv[1],O_RDONLY|O_WRONLY,666);
I find life an exciting business and most exciting when it is lived for others.
相关文章推荐
- CentOS下安装C/C++开发工具包的最佳方式
- 解决在Linuxmint18.1环境下fcitx无法显示候选框的问题
- linux内核(kernel)版本号的意义
- CentOS安装MySQL与登录退出
- 运维请注意:”非常危险“的Linux命令大全
- VM12+CentOS6.5+hadoop2.7.3 搭建hadoop完全分布式集群
- 在linux mint 18环境下解决wine安装软件中文乱码的问题
- Linux下有趣的命令
- SELinux阻止某些程序运行的处理方法
- SecureCRT在Linux服务器下怎么设置成可以高亮显示?
- linux下rz和sz用发详解
- Linux远程工具
- 菜鸟学Linux 第087篇笔记 配置ha web
- 06-1-linux下寻求帮助
- Linux终端下 dstat 监控工具
- vmware中centos7静态ip的设置
- 开发板linux中运行简单hello world应用程序的printf无输出的原因
- 开发板linux中运行简单hello world应用程序的printf无输出的原因
- 开发板linux中运行简单hello world应用程序的printf无输出的原因
- 开发板linux中运行简单hello world应用程序的printf无输出的原因