Issue
Is it possible to get the modification date and time of a folder?
I know you can use stat -f "%m" folder
, but it doesn't reflect sub-files/folders changes.
ls -l folder
- doesn't reflect changes inside the folderstat -f "%m" folder
- same as abovedate -r folder
- same againfind foo bar baz -printf
- theprintf
option doesn't exist on my version of find
Versions of things:
- OS: Mac OS X 10.7.1
- Bash: GNU bash, version 3.2.48(1)-release (x86_64-apple-darwin11)
Solution
Solution:
find . -exec stat -f "%m" \{} \; | sort -n -r | head -1
Explanation:
- the
find
command traverses the current directory (.
) and for each file encountered executes (-exec
) the commandstat -f "%m"
.stat -f "%m"
prints the last modification unix timestamp of the file. sort -n -r
sorts the output of thefind
command numerically (-n
) in reverse order (-r
). This will list the latest modification timestamp first.head -1
then extracts the first line of the output fromsort
. This is the latest modification unix timestamp of all the files.
Answered By - Tyilo Answer Checked By - Mildred Charles (WPSolving Admin)