日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 运维知识 > linux >内容正文

linux

linux touch更新文件时间,Linux文件时间的查看和修改touch

發布時間:2023/12/10 linux 47 豆豆
生活随笔 收集整理的這篇文章主要介紹了 linux touch更新文件时间,Linux文件时间的查看和修改touch 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

1. Linux文件的時間

Linux下文件時間主要有下面三種:

1.1 modification time(mtime)

文件修改時間,即文件內容的修改時,更新這個時間,不包括文件權限和屬性的修改。

使用ls -l查看,默認顯示時間為mtime

$ ls -l uconv.h

-rw-rw-r--? 1 work work 1808 Jul 23? 2013 uconv.h

1.2 status time(ctime)

文件狀態status的修改時間,如文件的權限和屬性修改時更新這個時間。

使用 ls --time=ctime 查看

$ ls -l --time=ctime uconv.h

-rw-rw-r--? 1 work work 1808 Jul 23? 2013 uconv.h

1.3 access time(atime)

文件訪問時間,當文件內容被獲取時,更新這個時間。

使用 ls --time=actime 查看

$ ls -l --time=atime uconv.h

-rw-rw-r--? 1 work work 1808 Dec 12? 2013 uconv.h

2. 修改文件的時間

如果需要修改上述三個時間,使用touch命令來修改。

touch filename ,如果文件不存在,則新建一個文件。

$ touch --help

Usage: touch [OPTION]... FILE...

Update the access and modification times of each FILE to the current time.

-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

修改mtime

-r, --reference=FILE? use this file's times instead of current time

-t STAMP? ? ? ? ? ? ? use [[CC]YY]MMDDhhmm[.ss] instead of current time

指定修改時間

例如:

$ touch -d "2 days ago" uconv.h

$ ll uconv.h ; ll --time=atime uconv.h ; ll --time=ctime uconv.h ;

-rw-rw-r--? 1 work work 1808 Jun 13 18:17 uconv.h

-rw-rw-r--? 1 work work 1808 Jun 13 18:17 uconv.h

-rw-rw-r--? 1 work work 1808 Jun 15 18:17 uconv.h

將mtime和atime修改為兩天前,ctime沒變。

$ touch -t 201406142020 uconv.h

$ ll uconv.h ; ll --time=atime uconv.h ; ll --time=ctime uconv.h ;

-rw-rw-r--? 1 work work 1808 Jun 14 20:20 uconv.h

-rw-rw-r--? 1 work work 1808 Jun 14 20:20 uconv.h

-rw-rw-r--? 1 work work 1808 Jun 15 18:23 uconv.h

atime和mtime都變了,但是ctime變成了當前時間。

使用cp命令,-a保持原屬性。

$ cp -a uconv.h uconv.h1

$ ll uconv.h1 ; ll --time=atime uconv.h1 ; ll --time=ctime uconv.h1 ;

-rw-rw-r--? 1 work work 1808 Jun 14 20:20 uconv.h1

-rw-rw-r--? 1 work work 1808 Jun 15 18:25 uconv.h1

-rw-rw-r--? 1 work work 1808 Jun 15 18:27 uconv.h1

mtime和atime都保持原文件不變,但是ctime變成當前時間

創作挑戰賽新人創作獎勵來咯,堅持創作打卡瓜分現金大獎

總結

以上是生活随笔為你收集整理的linux touch更新文件时间,Linux文件时间的查看和修改touch的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。