Answers:
如@ edvinas.me所述,它stat
告诉您有关文件的各种信息,包括最后修改日期。
起初,我对Modify和Change感到困惑,只是为了澄清stat
输出列表:
例如:
~ $ 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
如果文件在另一个Web服务器上,我喜欢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
(例如,超级用户似乎不这样做)。
1)列出文件目录和最后修改的日期/时间
要列出文件并在顶部显示最后修改的文件,我们将
-lt
在ls
命令中使用选项。$ ls -lt /run output total 24 -rw-rw-r--. 1 root utmp 2304 Sep 8 14:58 utmp -rw-r--r--. 1 root root 4 Sep 8 12:41 dhclient-eth0.pid drwxr-xr-x. 4 root root 100 Sep 8 03:31 lock drwxr-xr-x. 3 root root 60 Sep 7 23:11 user drwxr-xr-x. 7 root root 160 Aug 26 14:59 udev drwxr-xr-x. 2 root root 60 Aug 21 13:18 tuned
https://linoxide.com/linux-how-to/how-sort-files-date-using-ls-command-linux/
ls -l
也适用...