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