in linux terminal, how do I show the folder's last modification date, taking its content into consideration? in linux terminal, how do I show the folder's last modification date, taking its content into consideration? shell shell

in linux terminal, how do I show the folder's last modification date, taking its content into consideration?


Something like:

find /path/ -type f -exec stat \{} --printf="%y\n" \; |      sort -n -r |      head -n 1

Explanation:

  • the find command will print modification time for every file recursively ignoring directories (according to the comment by IQAndreas you can't rely on the folders timestamps)
  • sort -n (numerically) -r (reverse)
  • head -n 1: get the first entry


If you have a version of find (such as GNU find) that supports -printf then there's no need to call stat repeatedly:

find /some/dir -printf "%T+\n" | sort -nr | head -n 1

or

find /some/dir -printf "%TY-%Tm-%Td %TT\n" | sort -nr | head -n 1

If you don't need recursion, though:

stat --printf="%y\n" *


If I could, I would vote for the answer by Paulo. I tested it and understood the concept. I can confirm it works.The find command can output many parameters.For example, add the following to the --printf clause:

%a for attributes in the octal format%n for the file name including a complete path

Example:

find Desktop/ -exec stat \{} --printf="%y %n\n" \; | sort -n -r | head -12011-02-14 22:57:39.000000000 +0100 Desktop/new file

Let me raise this question as well:Does the author of this question want to solve his problem using Bash or PHP? That should be specified.