正如@edvinas.me所提到的,stat
告诉你关于文件的各种信息,包括最后一次修改的日期。
一开始,我把Modify和Change搞混了,只是为了澄清一下,stat
输出列表:
-Access显示最后一次数据访问的时间(如:读。 -Modify显示最后一次修改数据的时间 -Change显示最后一次改变文件状态的时间
例如:
~ $ touch foo
~ $ stat foo
File: ‘foo’
Size: 0 Blocks: 0 IO Block: 4096 regular empty file
Device: fc01h/64513d Inode: 410397 Links: 1
Access: (0644/-rw-r--r--) Uid: (80972/ etomort) Gid: (18429/ eem_tw)
Access: 2015-09-21 12:06:11.343616258 +0200
Modify: 2015-09-21 12:06:11.343616258 +0200
Change: 2015-09-21 12:06:11.343616258 +0200
Birth: -
~ $ echo "Added bar to foo file" >> foo
~ $ stat foo
File: ‘foo’
Size: 42 Blocks: 8 IO Block: 4096 regular file
Device: fc01h/64513d Inode: 410654 Links: 1
Access: (0644/-rw-r--r--) Uid: (80972/ etomort) Gid: (18429/ eem_tw)
Access: 2015-09-21 12:09:31.298712951 +0200
Modify: 2015-09-21 12:09:31.298712951 +0200
Change: 2015-09-21 12:09:31.302713093 +0200
Birth: -
~ $ chmod 444 foo
~ $ stat foo
File: ‘foo’
Size: 42 Blocks: 8 IO Block: 4096 regular file
Device: fc01h/64513d Inode: 410654 Links: 1
Access: (0444/-r--r--r--) Uid: (80972/ etomort) Gid: (18429/ eem_tw)
Access: 2015-09-21 12:09:31.298712951 +0200
Modify: 2015-09-21 12:09:31.298712951 +0200
Change: 2015-09-21 12:10:16.040310543 +0200
Birth: -
另一种比较灵活的方法是使用date -r
。从man date
:
-r, --reference=FILE
display the last modification time of FILE
这样做的好处是可以指定输出格式,例如:
$ date -r foo
Thu Aug 31 10:36:28 AEST 2017
$ date -r foo -R
Thu, 31 Aug 2017 10:36:28 +1000
$ date -r foo -u
Thu Aug 31 00:36:28 UTC 2017
$ date -r foo +%s
1504139788
ls -l
应该做的工作。
例:
#> ls -l /home/TEST/
total 16
-rw-r--r-- 1 rfmas1 nms 949 Nov 16 12:21 create_nd_lists.py
-rw-r--r-- 1 rfmas1 nms 0 Nov 16 12:35 enb_list
-rw-r--r-- 1 rfmas1 nms 0 Nov 16 12:35 nb_list
-rw-r--r-- 1 rfmas1 nms 0 Nov 16 12:35 nodes_ip.txt
-rw-r--r-- 1 rfmas1 nms 0 Nov 16 12:35 rnc_list
Building off of@Adam Taylor’s comment in @phoops’s answer and @Sparhawk’s answer.
stat -c %y file | cut -d' ' -f1
会给你2019-10-03
也会给你date +%F -r file
也会给你2019-10-03
也会给你date +%D -r file
也会给你10/03/19
也会给你date +%x -r file
也会给你10/03/2019
也会probably给你10/03/19
,如果你在美国,或者03/10/2019
也会给你03/10/19
,如果你在英国,或者date
也会给你`%‘:
>
> - (hyphen) do not pad the fieldN.B.: These flags don’t work on the “combo formats” like `。仅举几个例子(当然还有更多的可能性)
这些,
格式选项,据我的理解,是其他格式选项的组合。以下是 man page 的一些解释:
%b locale的月名缩写 (例如:Jan) %B locale的全月名 (例如:Jan) %B locale的全月名 (例如:Jan, 1月) …. %d月份的日期 (例如,01) %D日期;与%m/%d/%y相同 %e月份的日期,空格填充;与%d相同 %F完整的日期;与%Y-%m-%d相同 … %m月份 (01…12) … %x locale的日期表示 (例如, 12/31/99) …. %y年的最后两位数字 (00…99) %Y年 …. 默认情况下,日期填充数字字段为零。
下面的可选标志可以跟随and
%F`. They are for the “singular field formats_”.
Apparently this last flag ( # ) does not work as I’d expect (e.g., if %D
gives %D
, %x
gives date +%b
as opposed to Oct
) I guess this would be useless, but I’d think a lower case option would be more useful. date +%#b
does turn OCT
which might give oCT
or date +%#P
into 日期+%P
or PM
, respectively. So I guess it’s not a 'per-character’ case switch but sets the case of all the characters in the string to the opposite case of the majority of the characters? Also AM
gives AM
or 日期+%P
, but neither PM
nor AM
change its output. My guess for this case is that 日期+%^P
is just an alias for 日期+%#P
, and it seems that whenever you add more than one flag, the behavior is undefined/unpredictable ( e.g., %#P
gives the same as %#P
: 日期+%0- e
and date +%-e
gives the same as 3
: date +%-0e
, which makes you think that only the flag next to the letter works or that it goes left to right, but both date +%0e
and 03
give date +%#^p
or date +%^#p
, [depending on the time of course] ) unless there’s some hidden order of operations? Sorry for digressing…
Also, if you run the command pm
, you can see the combo for the specific locale of your system (e.g., am
).
And you can make your own combo. For example,
locale -k LC_TIME | grep ^d_fmt
will give you d_fmt="%m/%d/%Y"&007date +%^b %-e %Y -r file&007OCT 3 2019
如果文件在另一个webserver上,我喜欢httpie
docs)。
pip install httpie --user
-h
命令只给出了头。模式是
http -h [url] | grep 'Last-Modified\|Date'
示例:
$ http -h https://martin-thoma.com/author/martin-thoma/ | grep 'Last-Modified\|Date'
Date: Fri, 06 Jan 2017 10:06:43 GMT
Last-Modified: Fri, 06 Jan 2017 07:42:34 GMT
Date
这个命令很重要,因为它报告的是服务器时间,而不是你的本地时间。另外,不是每个服务器都会发送Last-Modified
(例如,超级用户似乎不会发送&007)。
1) 列出文件目录中的最后修改日期/时间
要列出文件,并在顶部显示最后修改的文件,我们将使用
-lt
选项和ls
命令。