文件操作(Linux系统编程)

创建一个目录时,系统会自动创建两个目录.和..

C语言实现权限控制函数

 #include<stdio.h>
 #include<stdlib.h>
 #include<sys/types.h>
 #include<sys/stat.h>

 int main(int argc , char **argv){
         int mode;
         int mode_u;
         int mode_g;
         int mode_o;
         char *path;

         ){
                 printf(]);
                 exit();
         }
                 //字符串转换成整型
         mode = atoi(argv[]);
          || mode < ){
                 printf("mode num error ! \n");
                 exit();
         }

         mode_u = mode / ;
         mode_g = (mode - (mode_u*)) / ;
         mode_o = mode - (mode_u*) - (mode_g*);
         mode = (mode_u *  * ) + (mode_g * ) + mode_o;
         path = argv[];
                 //改变权限函数
         ){
                 perror("chmod error");
                 exit();
         }

         ;
 }

 新建一个文件test.c
 命令:./程序   test.c

2.文件的输入输出函数

 #include<stdio.h>
 #include<sys/types.h>
 #include<sys/stat.h>
 #include<fcntl.h>
 #include<unistd.h>
 #include<errno.h>

 int main(){
         int fd;
                 //文件不存在创建文件
         ){
                //       if((fd = creat("example.c",S_IRWXU)) == -1){
               //        perror("open");
                         printf("open:%s with errno :%d \n", strerror(errno),errno);
                         exit();
                 }else{
                         printf("create file success\n");
                 }
                         //}

         close(fd);
         ;

 }

 my_creat.c: In function ‘main’:
 my_creat.c:: warning: incompatible implicit declaration of built-in function ‘exit’

3.文件的读写
文件读写和文件读写指针的移动操作

 #include<stdio.h>
 #include<sys/types.h>
 #include<sys/stat.h>
 #include<fcntl.h>
 #include<unistd.h>
 #include<errno.h>

 /**error handle function **/
 void my_err(const char *err_string , int line){
         fprintf(stderr,"line:%d",line);
         perror(err_string);
         exit();
 }
 /**read data function**/
 int my_read(int fd){
         int len;
         int ret;
         int i;
         ];
         /**get file length and save file-read-pointer to the head of file **/
          , SEEK_END) == -){
                 my_err("lseek",_LINE_);
         }
         ,SEEK_CUR)) == -){
                 my_err("lseek",_LINE_);
         }
         ,SEEK_SET)) == -){
                 my_err("lseek",_LINE_);
         }

         printf("len :%d\n",len);
         /**read data**/
         ){
                 my_err("read",_LINE_);
         }
         /**print data**/
          ; i < len ; i++){
                 printf("%c",read_buf[i]);
         }
         printf("\n");

         return ret;
 }
 int main(){
         int fd ;
         ] = "hello world!";
         /**create file in current dictionary**/
         ){
                 ){
                         my_err(,          Top
                }else{
                         printf("create file success!");
                 }
                 /*wirte data*/
                 if(wirte(fd,write_buf,strlen(write_buf)) != strlen(write_buf)){
                         my_err("write",_LINE_);
                 }
                 my_read(fd);

                 /**display file's space**/
                 printf("--------------------\n");
                 ,SEEK_END) == -){
                         my_err("lseek",_LINE_);
                 }

                 if(write(fd,write_buf,strlen(write_buf)) != strlen(write_buf)){
                         my_err("write",_LINE_);
                 }
                 my_read(fd);

                 close(fd);

                 ;
         }
 }

Linux C 程序 文件操作(Linux系统编程)(14)的更多相关文章

  1. 3)Linux程序设计入门--文件操作

    )Linux程序设计入门--文件操作 Linux下文件的操作 前言: 我们在这一节将要讨论linux下文件操作的各个函数. 文件的创建和读写 文件的各个属性 目录文件的操作 管道文件 .文件的创建和读 ...

  2. Linux学习记录--文件IO操作相关系统编程

    文件IO操作相关系统编程 这里主要说两套IO操作接口,各自是: POSIX标准 read|write接口.函数定义在#include<unistd.h> ISO C标准 fread|fwr ...

  3. Linux(三)__文件权限、系统的查找、文本编辑器

    一.文件权限 1.理解文件权限及其分配 2.掌握查看文件和目录的权限 3.掌握权限文字表示法和数值表示法 4.学会使用chmod命令设置权限 5.学会使用chown命令修改属主和组 linux文件能不 ...

  4. 5 个在 Linux 中管理文件类型和系统时间的有用命令

    对于想学习 Linux 的初学者来说要适应使用命令行或者终端可能非常困难.由于终端比图形用户界面程序更能帮助用户控制 Linux 系统,我们必须习惯在终端中运行命令.因此为了有效记忆 Linux 不同 ...

  5. 一、linux基础-对文件操作

    1.1文件夹创建-复制-移动-重命名-删除1.创建文件夹mkdir zjbdir 2.复制文件/文件夹复制文件到:当前目录cp -r zjbdir  zjbdir201600819复制文件到:当前目录 ...

  6. linux下的文件操作——批量重命名

    概述:在日常工作中,我们经常需要对一批文件进行重命名操作,例如将所有的jpg文件改成bnp,将名字中的1改成one,等等.文本主要为你讲解如何实现这些操作 1.删除所有的 .bak 后缀: renam ...

  7. Linux 目录和文件操作

    Linux常用命令--目录和文件操作 [目录]删除.复制.移动 : 1.删除文件夹用:rmdir 文件夹名 但是rmdir不能删除非空的文件夹,那如何删除非空文件夹呢: 2.通常情况下,删除文件用:r ...

  8. Linux下的文件操作——基于文件指针的文件操作(缓冲)

    目录操作 创建和删除目录: 原型为: #include <sys/stat.h> #include <sys/types.h> #include <unistd.h> ...

  9. Linux中gz文件操作遇到的一些技巧和坑

    目录 不解压情况下获取gz超大文件的前/后几行? Perl读入gz文件操作? 不能直接通过wc -l 来统计gz文件的行数 前提是gz文件超大,如上百G,肯定不能直接解压来做. 不解压情况下获取gz超 ...

随机推荐

  1. Android Configuration change属性

    问题:横竖屏切换时Activity的生命周期? 答案: 1.不设置Activity的android:configChanges时,切屏会重新调用各个生命周期,切横屏时会执行一次,切竖屏时会执行两次 2 ...

  2. WORD神操作!第一个技巧你就傻眼了!

    原文:http://mp.weixin.qq.com/s?__biz=MzA4NzkyMDIwNw==&mid=220128483&idx=4&sn=cfa87c941f36f ...

  3. c#_自动化测试 (五) 读写64位操作系统的注册表

    非Web程序(桌面程序)的设置一般都存在注册表中. 给这些程序做自动化测试时, 需要经常要跟注册表打交道. 通过修改注册表来修改程序的设置. 本章介绍如何利用C#程序如何操作注册表, 特别是如何操作6 ...

  4. android初学-togglebutton

    1.属性:textOn &textOff &checked 2.使用: 1)初始化:TB: 2)设置监听器:TB.setOnCheckedChangeListener(listener ...

  5. CSS skills: 3) show sub-navigate items when mouse hove on nav-item

    <header> <div class="am-g am-g-fixed"> <ul class="am-avg-lg-2 topbar f ...

  6. jboss加密敏感信息

    默认情况下,我们配置在domain.xml或host.xml文件中的信息都是明文,对一些敏感信息就显得安全性不够,可以使用jboss提供的vault机制来进行加密 下面的内容来自 http://www ...

  7. CF Drazil and Factorial (打表)

    Drazil and Factorial time limit per test 2 seconds memory limit per test 256 megabytes input standar ...

  8. Mysql打开日志信息

    还可参考博客:http://pangge.blog.51cto.com/6013757/1319304 1)怎么查看mysql是否启用了日志 mysql>show variables like ...

  9. 关于IE8不支持document.getElementById().innerHTML的问题

    document.getElementById("id").innerHTML = (showinfo);//IE8不支持. 可以用Jquery来解决这个问题: $('#id'). ...

  10. 【阔别许久的博】【我要开始攻数学和几何啦】【高精度取模+同余模定理,*】POJ 2365 The Embarrassed Cryptographer

    题意:给出一大数K(4 <= K <= 10^100)与一整数L(2 <= L <= 106),K为两个素数的乘积(The cryptographic keys are cre ...