关于nginx:在Linux中如何查看文件的修改日期

4次阅读

共计 2165 个字符,预计需要花费 6 分钟才能阅读完成。

有时候可能须要查看无关文件的详细信息,例如文件的批改日期。当你要查看文件的最初编辑工夫时,本文可能会派上用场。在本文将学习 4 种办法查看文件的批改日期。
应用 stat 命令
stat 命令能够显示文件属性的详细信息,比方最近一次拜访和批改文件的工夫、文件大小等信息,应用起来比较简单,命令前面只须要加上文件名就能够:

[root@localhost ~]# stat hello_script.sh
File:‘hello_script.sh’
Size: 31 Blocks: 8 IO Block: 4096 regular file
Device: fd00h/64768d Inode: 67169379 Links: 1
Access: (0755/-rwxr-xr-x) Uid: (0/ root) Gid: (0/ root)
Context: unconfined_u:object_r:admin_home_t:s0
Access: 2020-10-15 19:13:24.628009932 +0800
Modify: 2020-10-15 19:07:18.266426499 +0800
Change: 2020-10-15 19:11:48.227856412 +0800
Birth: –
在 Linux 中如何查看文件的批改日期在 Linux 中如何查看文件的批改日期
从下面的输入中,咱们能够看到文件的拜访日期、文件的批改日期、文件权限的批改日期以及其余参数。

如果只心愿查看文件的批改日期,而不思考所有其余信息,运行以下命令:

[root@localhost ~]# stat -c %y hello_script.sh
2020-10-15 19:07:18.266426499 +0800
在 Linux 中如何查看文件的批改日期在 Linux 中如何查看文件的批改日期
- c 选项用于指定自定义格局代替默认的输入,而 ’%y’ 标记显示上次批改工夫。对于文件夹,语法放弃不变。只需将文件名替换为文件夹名称即可。

应用 date 命令
date 命令的用法是显示以后日期。然而当与 - r 选项一起应用时,能够显示文件的最初批改日期,如下所示:

[root@localhost ~]# date -r hello_script.sh
Thu Oct 15 19:07:18 CST 2020
在 Linux 中如何查看文件的批改日期在 Linux 中如何查看文件的批改日期

应用 ls - l 命令
ls - l 命令通常用于应用长列表显示无关文件的其余信息,例如文件权限和所有者,大小和创立日期。能够增加 - t 选项,这样就能够依照文件的批改工夫来排列:

[root@localhost ~]# ls -lt
或者
[root@localhost ~]# ll -t

total 288
drwxr-xr-x. 2 root root 177 Oct 16 14:36 b
drwxr-xr-x. 2 root root 177 Oct 16 14:36 a
-rwxr-xr-x. 1 root root 119 Oct 15 19:20 backup_script.sh
-rwxr-xr-x. 1 root root 31 Oct 15 19:07 hello_script.sh
-rw-r–r–. 1 root root 227 Oct 13 16:39 content.txt
-rw-r–r–. 1 root root 277159 Oct 12 14:37 a.txt
drwxr-xr-x. 2 root root 195 Aug 6 14:12 Files
-rw——-. 1 root root 1284 Dec 29 2019 anaconda-ks.cfg
在 Linux 中如何查看文件的批改日期在 Linux 中如何查看文件的批改日期

应用 httpie 工具
另一种查看文件的批改日期的办法是应用 httpie,是 HTTP 命令行客户端工具。该工具通常用于与 HTTP 服务器和 API 交互,还能够查看驻留在 web 服务器上文件的批改工夫。

首先须要确保装置了 python 的 pip 包管理工具,而后装置 httpie 工具:

在 Centos7/RHEL7 中,运行以下命令装置 httpie:

[root@localhost ~]# yum -y install python-pip
[root@localhost ~]# pip install –upgrade pip
[root@localhost ~]# pip install httpie
在 Linux 中如何查看文件的批改日期在 Linux 中如何查看文件的批改日期
在 Ubuntu / Deepin / Debian 中运行以下命令装置 httpie:

$ sudo apt install httpie
装置实现之后,那么如何查看 web 服务器上文件的批改工夫呢?语法如下:

http -h [url] | grep ‘Last-Modified’
例如,从 www.linuxprobe.com 网站中,查看一张.png 格局的图片批改工夫:

[root@localhost ~]# http -h https://www.linuxprobe.com/wp… | grep -i ‘Last-Modified’
Last-Modified: Fri, 05 Jun 2020 14:26:11 GMT
在 Linux 中如何查看文件的批改日期在 Linux 中如何查看文件的批改日期

总结
在本文中,介绍了各种办法,能够应用这些办法列出文件的最初批改日期,甚至能够应用 httpie 工具列出 web 服务器上的文件的最初批改日期。

正文完
 0