[lingyun@localhost utime]$ ls
hello  utime.c  world

[lingyun@localhost utime]$ cat utime.c 

/*********************************************************************************

 *      Copyright:  (C) 2013 fulinux<fulinux@sina.com> 

 *                  All rights reserved.

 *

 *       Filename:  utime.c

 *    Description:  This file 

 *                 

 *        Version:  1.0.0(08/04/2013~)

 *         Author:  fulinux <fulinux@sina.com>

 *      ChangeLog:  1, Release initial version on "08/04/2013 05:49:04 PM"

 *                 

 ********************************************************************************/

#include <stdio.h>

#include <stdlib.h>

#include <string.h>

#include <unistd.h>

#include <fcntl.h>

#include <utime.h>

#include <sys/stat.h>

/********************************************************************************

 *  Description:

 *   Input Args:

 *  Output Args:

 * Return Value:

 ********************************************************************************/

int main (int argc, char **argv)

{

    int     i, fd;

    struct stat statbuf;

    struct utimbuf timebuf;

for(i = 1; i < argc; i++)

    {

        if(stat(argv[i], &statbuf) < 0)

        {

            printf ("%s: stat error\n", argv[i]);

            continue;

        }

        if((fd = open(argv[i], O_RDWR | O_TRUNC)) < 0)

        {

            printf ("%s: open error\n", argv[i]);

            continue;

        }

        close(fd);

        timebuf.actime  = statbuf.st_atime;

        timebuf.modtime = statbuf.st_mtime;

if(utime(argv[i], &timebuf) < 0)

        {

            printf ("%s: utime error\n", argv[i]);

            continue;

        }

    }

    exit(0);

} /* ----- End of main() ----- */

[lingyun@localhost utime]$ gcc utime.c 

[lingyun@localhost utime]$ ls -l hello world 

-rw-r--r-- 1 lingyun trainning 0 Aug  4 18:03 hello

-rw-r--r-- 1 lingyun trainning 0 Aug  4 18:04 world

[lingyun@localhost utime]$ ls -lu hello world 

-rw-r--r-- 1 lingyun trainning 0 Aug  4 18:03 hello

-rw-r--r-- 1 lingyun trainning 0 Aug  4 18:04 world

[lingyun@localhost utime]$ date

Sun Aug  4 18:10:44 CST 2013

[lingyun@localhost utime]$ ./a.out hello world 

[lingyun@localhost utime]$ ls -l hello world 

-rw-r--r-- 1 lingyun trainning 0 Aug  4 18:03 hello

-rw-r--r-- 1 lingyun trainning 0 Aug  4 18:04 world

[lingyun@localhost utime]$ ls -lu hello world 

-rw-r--r-- 1 lingyun trainning 0 Aug  4 18:03 hello

-rw-r--r-- 1 lingyun trainning 0 Aug  4 18:04 world

[lingyun@localhost utime]$ ls -lc hello world 

-rw-r--r-- 1 lingyun trainning 0 Aug  4 18:10 hello

-rw-r--r-- 1 lingyun trainning 0 Aug  4 18:10 world

[lingyun@localhost utime]$

linux之utime函数解析的更多相关文章

  1. Linux exec族函数解析

    背景 在提到 vfork 函数时,我们提到了这个概念.为了更好地学习与运用,我们对exec族函数进行展开. exec函数族 介绍 有时我们希望子进程去执行另外的程序,exec函数族就提供了一个在进程中 ...

  2. linux之unlink函数解析

    [lingyun@localhost unlink]$ cat unlink.c  /********************************************************* ...

  3. linux之access函数解析

    [lingyun@localhost access_1]$ ls access.c 实例一: [lingyun@localhost access_1]$ cat access.c  /******** ...

  4. linux之ioctl函数解析

    [lingyun@localhost ioctl_1]$ ls ipconfig.c [lingyun@localhost ioctl_1]$ cat ipconfig.c  /*********** ...

  5. linux之umask函数解析

    [lingyun@localhost umask_1]$ vim umask.c  + umask.c                                                 ...

  6. linux之chdir函数解析

    [lingyun@localhost chdir]$ ls chdir.c [lingyun@localhost chdir]$ cat chdir.c  /********************* ...

  7. linux之getcwd函数解析

    [lingyun@localhost getcwd]$ cat getcwd.c /********************************************************** ...

  8. linux之stat函数解析

    [lingyun@localhost stat_1]$ vim stat.c  + stat.c                                                     ...

  9. 关于Linux系统basename函数缺陷的思考

    某模块作为前台进程独立运行时,运行命令携带命令行参数:作为某平台下守护进程子进程运行时,需要将命令行参数固化在代码里.类似如下写法: char *argv[] = {"./DslDriver ...

随机推荐

  1. Android关闭系统锁屏

    昨晚探索了一下Android系统内的目录,意外发现系统锁屏的数据库 使用adb shell进入系统根目录 adb shell su sqlite3 data/system/locksettings.d ...

  2. Word 查找和替换的通配符

    查找和替换的通配符 若要查找 类型 示例 任意单个字符 ? s?t 可查找“sat”和“set”. 任意字符串 * s*d 可查找“sad”和“started”. 单词的开头 < <(in ...

  3. asp.net服务器控件防止多次提交问题

    用户可能点击多次提交按钮.这样,导致向数据库中插入了多条相同的记录. 好像这2个方法都是针对的服务器控件! //方法一:在提交时调用一段客户端的代码. function a() { document. ...

  4. call()与apply()区别

    一.方法的定义 call方法: 语法:call(thisObj,Object)定义:调用一个对象的一个方法,以另一个对象替换当前对象.说明:call 方法可以用来代替另一个对象调用一个方法.call ...

  5. android studio主题设置-笔记3

    主题背景设置(就是工具黑色背景还是白色背景),路径:File-Settings-Appearance

  6. iOS学习笔记(十四)——打电话、发短信

    电话.短信是手机的基础功能,iOS中提供了接口,让我们调用.这篇文章简单的介绍一下iOS的打电话.发短信在程序中怎么调用. 1.打电话 [[UIApplication sharedApplicatio ...

  7. Swift - 30 - 可变参数

    //: Playground - noun: a place where people can play import UIKit // 可变参数一定要放在所有定义参数的最后面, 和其他参数的定义方式 ...

  8. Swift - 26 - 函数的基础写法

    //: Playground - noun: a place where people can play import UIKit // 无参无返回 // -> Void可以省略不写, 或者写成 ...

  9. 03C#基础(2)

    1.比较运算符 ==等于;  !=不等于;  >大于;  >=大于或者等于;  <小于;  <=小于或者等于; 比较运算符(又称关系运算符)用来进行值得真假性判断,结果是boo ...

  10. cas sso单点登录系列2:cas客户端和cas服务端交互原理动画图解,cas协议终极分析

    转:http://blog.csdn.net/ae6623/article/details/8848107 1)PPT流程图:ppt下载:http://pan.baidu.com/s/1o7KIlom ...