Chinaunix首页 | 论坛 | 博客
  • 博客访问: 67580
  • 博文数量: 29
  • 博客积分: 98
  • 博客等级: 民兵
  • 技术积分: 160
  • 用 户 组: 普通用户
  • 注册时间: 2011-12-02 00:18
文章分类
文章存档

2012年(13)

2011年(16)

我的朋友

分类:

2012-02-06 22:41:49

原文地址:linux文件的时间 作者:linux_kaige


Linux文件有3个修改时间:

  1)modification time (mtime,修改时间):这个时间指的是文件内容修改的时间,而不是文件属性的修改,当数据内容修改时,这个时间就会改变,用命令ls -l默认显示的就是这个时间:
  2)status time (ctime,状态时间):当一个文件的状态改变时,这个时间就会改变,例如更改了文件的权限与属性等,它就会改变。
  3)access time (atime,访问时间):当读取文件内容时,就会更改这个时间,例如使用cat 去读取/etc/man.config,那么该文件的atime就会改变。
  1. [yangkai@admin ~]$ stat test.txt
  2. File: `test.txt'
  3. Size: 259 Blocks: 16 IO Block: 4096 regular file
  4. Device: fd00h/64768d Inode: 36732938 Links: 1
  5. Access: (0644/-rw-r--r--) Uid: ( 505/ yangkai) Gid: ( 0/ root)
  6. Access: 2012-02-16 18:01:00.000000000 +0800
  7. Modify: 2011-12-29 16:02:00.000000000 +0800
  8. Change: 2011-12-29 16:02:00.000000000 +0800
  9. [yangkai@admin ~]$
  1. root@admin ~]# touch --help
  2. Usage: touch [OPTION]... FILE...
  3. Update the access and modification times of each FILE to the current time.
  4. Mandatory arguments to long options are mandatory for short options too.
  5. -a change only the access time
  6. -c, --no-create do not create any files
  7. -d, --date=STRING parse STRING and use it instead of current time
  8. -f (ignored)
  9. -m change only the modification time
  10. -r, --reference=FILE use this file's times instead of current time
  11. -t STAMP use [[CC]YY]MMDDhhmm[.ss] instead of current time
  12. --time=WORD change the specified time:
  13. WORD is access, atime, or use: equivalent to -a
  14. WORD is modify or mtime: equivalent to -m
  15. --help display this help and exit
  16. --version output version information and exit
  17. Note that the -d and -t options accept different time-date formats.
  18. If a FILE is -, touch standard output.
  19. Report bugs to .
  20. [root@admin ~]#
  21. [root@admin testa]# ll
  22. total 8
  23. -rwxr-xr-x 1 root root 642 Feb 6 15:23 email-testyk.sh
  24. [root@admin testa]# touch -d "1 day ago" email-testyk.sh
  25. [root@admin testa]# ll
  26. total 8
  27. -rwxr-xr-x 1 root root 642 Feb 5 15:23 email-testyk.sh
  28. [root@admin testa]# touch email-testyk.sh
  29. [root@admin testa]# ll
  30. total 8
  31. -rwxr-xr-x 1 root root 642 Feb 6 15:23 email-testyk.sh
  32. [root@admin testa]#
  33. #ls -l --time=atime ./
  34. #ls -l --time=ctime ./
  35. #ls -l --time=mtime ./
touch的用法为:
  touch [-actmd] 文件
  参数:
  -a:仅修改access time
  -c:仅修改时间而不建立文件
  -t:后面可以接时间,格式为:[YYMMDDhhmm]
  -m:仅修改mtime
  -d:后面可以接日期,也可以使用--date="日期或时间"
通过touch命令,可以轻松的修改文件文件的日期与时间,atime和mtime将会改变而ctime不会改变,并且也可以建立一个空文件,复制一个文件并复制所有属性也不能复制其ctime属性。
注:linux复制文件的属性由当前用户的umask决定,复制会改变其ctime、atime、mtime。
  1. [yangkai@admin ~]$ stat DPIǚ±.17\(10т\).xlsx
  2. File: `DPI\271\343\270\346\315\306\313\315\305\305\306\355_2.17(10\265\343\270\374\320\302).xlsx'
  3. Size: 4021023 Blocks: 7872 IO Block: 4096 regular file
  4. Device: fd00h/64768d Inode: 36733008 Links: 1
  5. Access: (0644/-rw-r--r--) Uid: ( 0/ root) Gid: ( 0/ root)
  6. Access: 2012-02-17 11:05:20.000000000 +0800
  7. Modify: 2012-02-17 11:05:20.000000000 +0800
  8. Change: 2012-02-17 11:05:20.000000000 +0800
  9. [yangkai@admin ~]$ cp DPIǚ±.17\(10т\).xlsx awkdir/
  10. [yangkai@admin ~]$ stat awkdir/DPIǚ±.17\(10т\).xlsx
  11. File: `awkdir/DPI\271\343\270\346\315\306\313\315\305\305\306\355_2.17(10\265\343\270\374\320\302).xlsx'
  12. Size: 4021023 Blocks: 7872 IO Block: 4096 regular file
  13. Device: fd00h/64768d Inode: 36733011 Links: 1
  14. Access: (0644/-rw-r--r--) Uid: ( 505/ yangkai) Gid: ( 0/ root)
  15. Access: 2012-02-17 11:20:17.000000000 +0800
  16. Modify: 2012-02-17 11:20:17.000000000 +0800
  17. Change: 2012-02-17 11:20:17.000000000 +0800
  18. [yangkai@admin ~]$ rm awkdir/DPIǚ±.17\(10т\).xlsx
  19. [yangkai@admin ~]$ chmod +w DPIǚ±.17\(10т\).xlsx
  20. chmod: changing permissions of `DPI\271\343\270\346\315\306\313\315\305\305\306\355_2.17(10\265\343\270\374\320\302).xlsx': Operation not permitted
  21. [yangkai@admin ~]$ sudo chmod +w DPIǚ±.17\(10т\).xlsx
  22. [sudo] password for yangkai:
  23. [yangkai@admin ~]$ cp DPIǚ±.17\(10т\).xlsx awkdir/
  24. [yangkai@admin ~]$ stat awkdir/DPIǚ±.17\(10т\).xlsx
  25. File: `awkdir/DPI\271\343\270\346\315\306\313\315\305\305\306\355_2.17(10\265\343\270\374\320\302).xlsx'
  26. Size: 4021023 Blocks: 7872 IO Block: 4096 regular file
  27. Device: fd00h/64768d Inode: 36733011 Links: 1
  28. Access: (0644/-rw-r--r--) Uid: ( 505/ yangkai) Gid: ( 0/ root)
  29. Access: 2012-02-17 11:21:28.000000000 +0800
  30. Modify: 2012-02-17 11:21:29.000000000 +0800
  31. Change: 2012-02-17 11:21:29.000000000 +0800
  32. [yangkai@admin ~]$
在写一个技巧,cu上看的,查看history执行的时间,先执行“[yangkai@admin ~]$ HISTTIMEFORMAT="%Y-%m-%d %H:%M:%S"”,然后执行:“[yangkai@admin ~]$ history ”,结果信息:
  1. 737 2012-02-23 22:05:09awk 'BEGIN{FS=".";OFS="."}{if($4=="cn")print $(NF-2),$(NF-1),$(NF);else print $(NF-1),$(NF)}' urltest
  2. 738 2012-02-23 22:05:09awk 'BEGIN{FS=".";OFS="."}{if($4=="cn")print $(NF-2),$(NF-1);else print $(NF-1),$(NF)}' urltest
  3. 739 2012-02-23 22:05:12awk -W
  4. 740 2012-02-23 22:05:19awk --version
  5. 741 2012-02-23 22:39:29echo ""
  6. 742 2012-02-23 22:39:29HISTTIMEFORMAT
  7. 743 2012-02-23 22:39:36echo ""
  8. 744 2012-02-23 22:39:47echo " HISTTIMEFORMAT"
  9. 745 2012-02-23 22:40:02echo " HISTTIMEFORMAT" | tr '[A-Z]' '[a-z]'
  10. 746 2012-02-23 22:40:11histtimeformat
  11. 747 2012-02-23 22:40:24HISTTIMEFORMAT="%Y-%m-%d %H:%M:%S"
  12. 748 2012-02-23 22:40:27history

阅读(671) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~