在Linux中如何檢視檔案的修改日期
有時候可能需要檢查有關檔案的詳細資訊,例如檔案的修改日期。當你要檢查檔案的最後編輯時間時,本文可能會派上用場。在本文將學習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: -
從上面的輸出中,我們可以看到檔案的訪問日期、檔案的修改日期、檔案許可權的修改日期以及其他引數。
如果只希望檢視檔案的修改日期,而不考慮所有其他資訊,執行以下命令:
[root@localhost ~]# stat -c %y hello_script.sh 2020-10-15 19:07:18.266426499 +0800
-c
選項用於指定自定義格式代替預設的輸出,而'%y'標誌顯示上次修改時間。對於資料夾,語法保持不變。只需將檔名替換為資料夾名稱即可。
使用date命令
date命令的用法是顯示當前日期。但是當與-r
選項一起使用時,可以顯示檔案的最後修改日期,如下所示:
[root@localhost ~]# date -r hello_script.sh Thu Oct 15 19:07:18 CST 2020
使用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
使用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
在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-content/uploads/2020/06/6-1.png | grep -i 'Last-Modified' Last-Modified: Fri, 05 Jun 2020 14:26:11 GMT
總結
在本文中,介紹了各種方法,可以使用這些方法列出檔案的最後修改日期,甚至可以使用httpie工具列出web伺服器上的檔案的最後修改日期。
「其他文章」
- findmnt命令查詢已掛載的檔案系統
- 在Linux中如何檢視檔案的修改日期
- 用FRP做內網穿透使用遠端桌面連線家裡的windows電腦
- SUSE Linux 的Zypper包管理器使用例項
- 如何使用nload實時監控網路頻寬
- 如何使用awk處理文字內容
- 如何將CentOS 8轉換為CentOS Stream
- 如何自動接受SSH金鑰指紋?
- 夏天到了用TypeScript給自己開個小空調吧
- Bash Shell指令碼中的陣列使用例項
- Linux系統中的basename命令使用例項
- centos8使用chrony作為NTP伺服器
- Linux中如何使用Aria2下載檔案
- Centos8 如何配置DHCP伺服器
- 如何在Shell指令碼中逐行讀取檔案
- 使用Systemctl命令來管理系統服務
- 使用lsblk命令列出系統中的塊裝置
- 如何在Linux中使用 Truncate 命令
- Centos8種如何更改執行級別
- Zeit – Linux圖形化中定時任務的工具