开发者

Get folder (or sub-files/folders) last modification date and time

开发者 https://www.devze.com 2023-03-30 12:11 出处:网络
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.

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.

Things that doesn't work:

  • ls -l folder - doesn't reflect changes inside the folder
  • stat -f "%m" folder - same as above
  • date -r folder - same again
  • find foo bar baz -printf - the printf 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:

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

Explanation:

  1. the find command traverses the current directory (.) and for each file encountered executes (-exec) the command stat -f "%m". stat -f "%m" prints the last modification unix timestamp of the file.
  2. sort -n -r sorts the output of the find command numerically (-n) in reverse order (-r). This will list the latest modification timestamp first.
  3. head -1 then extracts the first line of the output from sort. This is the latest modification unix timestamp of all the files.


You could try 'date -r folder' to give you a date last modified


You could always get it from ls :

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


if you need to clear cache after build . then you can check the age of the last change and delete it like this

sh("find ~/Library/Developer/Xcode/DerivedData/ -type d -maxdepth 1 -mmin +360 -name 'Cache-folder-*' -print0 | xargs -0 -I {} /bin/rm -rf '{}' || echo 'There is no such folder! Start script execution' ; exit 0")



sh("find ~/Library/Developer/Xcode/DerivedData/ -type d -maxdepth 1 -mtime 0 -name 'Cache-folder-*' -ls -exec rm -r {} \\;")

0

精彩评论

暂无评论...
验证码 换一张
取 消