[英]in linux terminal, how do I show the folder's last modification date, taking its content into consideration?
所以這就是交易。 假設我有一個名為“web”的目錄,所以
$ ls -la
drwx------ 4 rimmer rimmer 4096 2010-11-18 06:02 web
但是在這個目錄中,web/php/
$ ls -la
-rw-r--r-- 1 rimmer rimmer 1957 2011-01-05 08:44 index.php
這意味着即使我的目錄 /web/php/index.php 的內容最后一次修改是在 2011-01-05,但 /web/ 目錄本身被報告為最后一次修改是在 2010-11-18。
我需要做的是將我的 /web/ 目錄的最后修改日期報告為該目錄中任何文件/目錄的最新修改日期,遞歸。
我該怎么做?
類似的東西:
find /path/ -type f -exec stat \{} --printf="%y\n" \; |
sort -n -r |
head -n 1
說明:
如果您有支持-printf
的find
版本(例如 GNU find
),則無需重復調用stat
:
find /some/dir -printf "%T+\n" | sort -nr | head -n 1
或
find /some/dir -printf "%TY-%Tm-%Td %TT\n" | sort -nr | head -n 1
但是,如果您不需要遞歸:
stat --printf="%y\n" *
如果可以,我會投票支持保羅的答案。 我測試了它並理解了這個概念。 我可以確認它有效。 find
命令可以輸出很多參數。 例如,將以下內容添加到--printf
子句中:
%a for attributes in the octal format
%n for the file name including a complete path
示例:
find Desktop/ -exec stat \{} --printf="%y %n\n" \; | sort -n -r | head -1
2011-02-14 22:57:39.000000000 +0100 Desktop/new file
我也提出這個問題:這個問題的作者是想用Bash還是PHP來解決他的問題? 這應該被指定。
在我看來,這很簡單: ls -lt mydirectory
完成了這項工作......
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.