Is it possible to get the modification date and time of a folder?
I know you can usestat -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 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:
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.
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 {} \\;")
精彩评论