How can I get the last time any of the files in a directory or its subdirectories has changed?
e.g
Dir - changed 1/1/1
Sub Dir 1 - changed 2/1/1
Sub Dir 2 - changed 3/1/1
File 1 - changed 10/1/1
File 2 - change 5/1/1
The output for this for Dir
should be 10/1/1 (File 1
was the last modified one). Getting the last file name to be modified is a bonus but isn't necessary.
Best Answer
find <dir> -type f -printf '%T@\t%p\n' | sort -r -k1 | head -n1
returns a line in the form:Alias or put in a script like in the following example to print file name or date.
Let's create a testing tree:
Get date of
a
:Get path of the file:
[1]: See Unix time on Wikipedia for an explanation of "Unix epoch".
Script example:
Call with or without
<dir>
as argument. It will use the current directory without.