[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. python文件处理--笔记

    之前一段时间一直在忙着写毕业论文,盲评搞得人心惶惶,以致于都没有看书,最近需要补上前面落下的东西. <Python3程序开发指南> 1.二进制数据的读写 二进制格式通常是占据磁盘空间最小. ...

  2. Android深入浅出之 AudioTrack分析

    Android深入浅出之Audio 第一部分 AudioTrack分析 一 目的 本文的目的是通过从Audio系统来分析Android的代码,包括Android自定义的那套机制和一些常见类的使用,比如 ...

  3. java编程思想-注解思维导图

  4. MVC3中 ViewBag、ViewData和TempData的使用和区别(不是自己写的)

    (网上抄的,并未消化)在MVC3开始,视图数据可以通过ViewBag属性访问,在MVC2中则是使用ViewData.MVC3中保留了ViewData的使用.ViewBag 是动态类型(dynamic) ...

  5. (转)php中GD库的配置,解决dedecms安装中GD不支持问题

    了解gd库 在php中,使用gd库来对图像进行操作,gd库是一个开放的动态创建的图像的源代码公开的函数库,可以从官方网站http://www.boutell.com/gd处下载.目前,gd库支持gif ...

  6. linux common command.

    Stopping & Starting shutdown -h now – Shutdown the system now and do not reboothalt – Stop all p ...

  7. iOS App完整项目

    前言 iOS开发学习者都希望得到实战训练,但是很多资料都是只有一小部分代码,并不能形成完成的App,笔者在此处收集了很多开源的完整的App,都有源代码哦! 完整项目 Phonetic Swift 写的 ...

  8. [技术翻译]Guava-libraries(一): 用户指导

    用户指导 本文翻译自http://code.google.com/p/guava-libraries/wiki/GuavaExplained,由十八子将翻译,发表于博客园 http://www.cnb ...

  9. css命名为何不推荐使用下划线_

    一直习惯了在命名CSS样式名时使用下划线“_”做为单词的分隔符,这也是在写JS时惯用的写法. 用过CSS hack的朋友应该知道,用下划线命名也是一种hack,如使用“_style”这样的命名,可以让 ...

  10. sql 语句左连接右连接小例子

    A表(a1,b1,c1) B表(a2,b2) a1 b1 c1 a2 b2 01 数学 95 01 张三 02 语文 90 02 李四 03 英语 80 04 王五 select A.*,B.* fr ...