linux下查看和修改文件时间
一、查看文件时间及相关命令
1、stat查看文件时间
[root@web10 ~]# stat install.log
File: “install.log”
Size: 33386 Blocks: 80 IO Block: 4096 一般文件
Device: fd00h/64768d Inode: 7692962 Links: 1
Access: (0644/-rw-r--r--) Uid: ( 0/ root) Gid: ( 0/ root)
Access: 2012-07-13 16:02:34.000000000 +0800
Modify: 2011-11-29 16:03:06.000000000 +0800
Change: 2011-11-29 16:03:08.000000000 +0800
说明:Access访问时间。Modify修改时间。Change状态改变时间。可以stat *查看这个目录所有文件的状态。
而我们想要查看某文件的三个时间中的具体某个时间,并以年月日时分秒的格式保存。我们可以使用下面的命令:
[root@web10 ~]# stat install.log|grep -i Modify | awk -F. '{print $1}' | awk '{print $2$3}'| awk -F- '{print $1$2$3}' | awk -F: '{print $1$2$3}'
20111129160306
2、ls查看文件时间
相应的通过ls 查看时也有三个时间:
• modification time(mtime,修改时间):当该文件的“内容数据”更改时,就会更新这个时间。内容数据指的是文件的内容,而不是文件的属性。
• status time(ctime,状态时间):当该文件的”状态(status)”改变时,就会更新这个时间,举例来说,更改了权限与属性,就会更新这个时间。
• access time(atime,存取时间):当“取用文件内容”时,就会更新这个读取时间。举例来说,使用cat去读取 ~/.bashrc,就会更新atime了。
[root@web10 ~]# ls -l --time=ctime install.log
-rw-r--r-- 1 root root 33386 2011-11-29 install.log
[root@web10 ~]# ls -l --time=atime install.log
-rw-r--r-- 1 root root 33386 07-13 16:02 install.log
注意:ls参数里没有--mtime这个参数,因为我们默认通过ls -l查看到的时间就是mtime 。
二、修改文件时间
创建文件我们可以通过touch来创建。同样,我们也可以使用touch来修改文件时间。touch的相关参数如下:
-a : 仅修改access time。
-c : 仅修改时间,而不建立文件。
-d : 后面可以接日期,也可以使用 --date="日期或时间"
-m : 仅修改mtime。
-t : 后面可以接时间,格式为 [YYMMDDhhmm]
注:如果touch后面接一个已经存在的文件,则该文件的3个时间(atime/ctime/mtime)都会更新为当前时间。若该文件不存在,则会主动建立一个新的空文件。
[root@web10 ~]# touch install.log
[root@web10 ~]# stat install.log
File: “install.log”
Size: 33386 Blocks: 80 IO Block: 4096 一般文件
Device: fd00h/64768d Inode: 7692962 Links: 1
Access: (0644/-rw-r--r--) Uid: ( 0/ root) Gid: ( 0/ root)
Access: 2012-07-13 16:21:50.000000000 +0800
Modify: 2012-07-13 16:21:50.000000000 +0800
Change: 2012-07-13 16:21:50.000000000 +0800
同样,使用ls ,查看到的结果也一样。
[root@web10 ~]# ls -l --time=ctime install.log
-rw-r--r-- 1 root root 33386 07-13 16:21 install.log
[root@web10 ~]# ls -l --time=atime install.log
-rw-r--r-- 1 root root 33386 07-13 16:21 install.log
[root@web10 ~]# ls -l install.log
-rw-r--r-- 1 root root 33386 07-13 16:21 install.log
下面再看一个和touch不相关的例子:
[root@web10 ~]# cp /etc/profile .;ll --time=atime profile ;ll --time=ctime profile
cp:是否覆盖“./profile”? y
-rw-r--r-- 1 root root 1344 07-13 16:24 profile
-rw-r--r-- 1 root root 1344 07-13 16:25 profile
因为我之前运行过这个命令一次,所以会出现覆盖,不过这个覆盖出的好,刚才让我们看到了atime和ctime的时间的差别。
我们再回到touch利用touch修改文件时间:
1. 同时修改文件的修改时间和访问时间
touch -d "2010-05-31 08:10:30" install.log
2. 只修改文件的修改时间
touch -m -d "2010-05-31 08:10:30" install.log
3. 只修改文件的访问时间
touch -a -d "2010-05-31 08:10:30" install.log
下面再给一个rootkit木马常用的伎俩。就是把后一个文件的时间修改成和前一个相同。
touch -acmr /bin/ls /etc/sh.conf
另外touch还支持像date命令一样参数修改文件时间:
[root@web10 ~]# touch -d "2 days ago" install.log ; ll install.log
-rw-r--r-- 1 root root 33386 07-11 16:35 install.log
最后总结下常用的文件操作与时间的关系:
1、访问时间,读一次这个文件的内容,这个时间就会更新。比如对这个文件使用more命令。ls、stat命令都不会修改文件的访问时间。
2、修改时间,对文件内容修改一次,这个时间就会更新。比如:vim后保存文件。ls -l列出的时间就是这个时间。
3、状态改变时间。通过chmod命令更改一次文件属性,这个时间就会更新。查看文件的详细的状态、准确的修改时间等,可以通过stat命令 文件名。
linux下查看和修改文件时间的更多相关文章
- (转)Linux 下 查看以及修改文件权限
场景:Linux环境下远程部署项目,发现因为文件权限问题,不能执行远端的可执行文件.问题还没解决,待议... 1 查看权限 在终端输入: ls -l xxx.xxx (xxx.xxx是文件名) 那么就 ...
- Linux 下 查看以及修改文件权限
查看权限 在终端输入: ls -l xxx.xxx (xxx.xxx是文件名) 那么就会出现相类似的信息,主要都是这些: -rw-rw-r-- 其中: 最前面那个 - 代表的是类型 中间那三个 rw- ...
- Linux下查看alert日志文件的两种方法
--linux下查看alert日志文件的两种方法: --方法1: SQL> show parameter background_dump_dest; NAME TYPE VALUE ------ ...
- Linux查看和修改文件时间
参考http://www.361way.com/chang-file-time/1632.html 一:查看时间 1:查看文件的具体时间信息 File: `probn' Size: Blocks: I ...
- linux 查看和修改文件时间
参考:https://www.cnblogs.com/chjbbs/p/6437879.html?utm_source=itdadao&utm_medium=referral . 同时修改文件 ...
- Linux下查看根目录各文件内存占用情况
一.服务器运行一点时间后各种的项目文件,日志文件,数据库备份登,会越来越多,在linux下可以使用 du 和 df 命令查看. 1.df -h 命令查看整体磁盘使用情况 2. 使用 du -ah -- ...
- linux下查看动态链接库so文件的依赖的相关组建
我们很多c程序在windows下是以dll形式展现的,在linux则是以so 形式展现的. windows一般不会因为编译dll文件的编译器版本不同而出先dll文件不能执行. 但是linux下,不同版 ...
- linux下查看doc在线帮助文件
常看到某个linux下的工具,有带有doc结尾的文件,但是新手不知道如何查看. 我一番查找,终于知道了... 比如:ipython这个软件,在ubuntu里面,有ipython-doc的一个包. 安装 ...
- Linux下查看与修改mtu值
MTU:通信术语 最大传输单元(Maximum Transmission Unit)是指一种通信协议的某一层上面所能通过的最大数据包大小(以字节为单位). 我们在使用互联网时进行的各种网络操作,都是通 ...
随机推荐
- win7凭据管理、win7多用户远程登录、主机头设置、nuget.org无法访问
前言 最近遇到的几个问题,然后处理在此对处理方式进行记录一下. 1.服务器共享文件夹,在本机进行访问登录时,每次登录或者每次开机进入都要进行登录的权限认证,这样很麻烦. 2.服务器难免会有多用户同时 ...
- Material Designer的低版本兼容实现(八)—— Flat Button
除了中规中矩的矩形按钮外,5.0中将按钮扁平化,产生了一个扁平按钮——Flat Button.这个按钮降低了很多存在感,主要用于在对话框,提示栏中.让整个界面减少层级.今天说的就是它的用法. 这 ...
- attrs.xml中declare-styleable 详解(用于自定义控件的属性)
1. 框架定义: <declare-styleable name = "名称"> <attr name = "……" format = &qu ...
- Netty 4.0.0.CR6 发布,高性能网络服务框架
Netty 4.0 发布第 6 个 RC 版本,该版本值得关注的改进有: SslHandler and JZlibEncoder now works correctly. (#1475 and #14 ...
- RV32A指令集
RV32A指令包括两类:AMO(atomic memory operation)指令,Load-Reserved/Store-Conditional指令 Category Fmt RV32I base ...
- Pytorch多GPU并行处理
可以参数2017coco detection 旷视冠军MegDet: MegDet 与 Synchronized BatchNorm PyTorch-Encoding官方文档对CGBN(cross g ...
- 领扣-754 到达终点数字 Reach a Number MD
Markdown版本笔记 我的GitHub首页 我的博客 我的微信 我的邮箱 MyAndroidBlogs baiqiantao baiqiantao bqt20094 baiqiantao@sina ...
- Android -- isInEditMode
解释 Indicates whether this View is currently in edit mode. A View is usually in edit mode when displa ...
- Provider Pattern for Beginners in .net
Download ProviderPattern.zip Introduction Provider pattern allows the developers to create pluggable ...
- PHP Manager for IIS
SOAP error on IIS8 Registering new PHP version sets bad values set for FastCGI activityTimeout, requ ...