[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. 转载:C#中事件和委托的编译代码

    接上文转载:C#中事件的由来,这时候,我们注释掉编译错误的行,然后重新进行编译,再借助Reflactor来对 event的声明语句做一探究,看看为什么会发生这样的错误: public event Gr ...

  2. angular中ueditor插件的使用

    #在angularjs中使用ueditor编辑器需要注意事项: 在ui-view中使用放置ueditor的div,页面加载时编辑器在页面中是不显示的,需要通过指令手动replay 例: /** * u ...

  3. Spring配置静态目录

    mvc-dispatcher-servlet.xml文件 <beans xmlns="http://www.springframework.org/schema/beans" ...

  4. Linq101-Quantifiers

    using System; using System.Collections.Generic; using System.Linq; namespace Linq101 { class Quantif ...

  5. Mock和injectMocks的区别

    @Mock private ForeCatalogManageServiceImpl foreCatalogManageServiceImpl; 如果是上面的写法,那么 红框方法里面的代码不会执行,这 ...

  6. 使用<pre>标签为你的网页加入大段代码

    在上节中介绍加入一行代码的标签为<code>,但是在大多数情况下是需要加入大段代码的,如下图: 怎么办?不会是每一代码都加入一个<code>标签吧,没有这么复杂,这时候就可以使 ...

  7. CSS 布局Float 【0】

    float是 css 样式的定位属性.我们在印刷排版中,文本可以按照需要围绕图片.一般把这种方式称为“文本环绕”.在网页设计中,应用了CSS的float属性的页面元素就像在印刷布局里面的被文字包围的图 ...

  8. hive 桶相关特性分析

    1. hive 桶相关概念     桶(bucket)是指将表或分区中指定列的值为key进行hash,hash到指定的桶中,这样可以支持高效采样工作.     抽样( sampling )可以在全体数 ...

  9. jquery 文本框聚焦文字删除

    做作业需要,自己写了一个,写的很烂. $(function() { $("#search_input").addClass("before_focus");/* ...

  10. 初涉JavaScript模式 (9) : 函数 【常用方式】

    回调模式 上一篇,对JavaScript函数进行了大体的介绍,这一篇对一些在工作中经常遇到的情况进行扩展. 在工作中,我们经常遇到很多需求,比如现在有一个需求: 一栋10层的大楼,当我们在坐电梯时,电 ...