Get the latest date and time the folder (or subfiles / folders) was changed

Can I get the date and time the folder was changed?
I know that you can use stat -f "%m" folder , but it does not reflect file / folder changes.

Things that don't work:

  • ls -l folder - does not reflect changes inside the folder
  • stat -f "%m" folder - same as above
  • date -r folder - again
  • find foo bar baz -printf - the printf option does not exist in 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)
+8
bash macos
source share
3 answers

Decision:

 find . -exec stat -f "%m" \{} \; | sort -n -r | head -1 

Explanation:

  • the find moves the current directory ( . ) and for each file it encounters ( -exec ) the stat -f "%m" command. stat -f "%m" prints the last unix file timestamp.
  • sort -n -r sorts the result of the find numerically ( -n ) in reverse order ( -r ). First, the last change timestamp will be indicated.
  • head -1 then extracts the first line of output from sort . This is the last unix timestamp of all files.
+13
source share

You can try "date -r folder" to indicate the date of the last change.

+5
source share

You can always get it from ls :

 ls -ld mydir | awk -F' ' '{ print $6 " "$7 }' 
0
source share

All Articles