|
mac geekeryGet your geek on. |
Determining Active File Use Over TimeSeptember 5, 2006 - 12:35pm
grizzlydom@earthlink.net asks: QuestionHow can I can calculate the accumulative size of all files accessed on a given volume in a give amount of time, say one month or one week? It is my hope that I can run the command/script and say, “we have X gigabytes worth of files actively used on volume Y every month.” AnswerSpotlight does this for you, really. As files are accessed, Spotlight updates its database with the last access time for every file. All you need to do is query that database to get the right answer from it and then pass the files to shell tools to do the rest. It’s another handy one-liner. The tool to use to query Spotlight is $ mdfind '(kMDLastUsedDate > $time.this_month)' This will return a list of files used in the last month. It’s downhill from there. Send that to $ mdfind -0 '(kMDItemLastUsedDate > $time.this_week)' | xargs -0 du -csk So, we’re telling Of course, as-is we have a small problem in that every file on the system is checked, including system files. This doesn’t sound like what you want. Handily, $ mdfind -onlyin /Shared\ Items -0 '(kMDItemLastUsedDate > $time.this_week)' | xargs -0 du -csk Now it only searches “Shared Items” for the files. That’s probably more along the lines of what you want. About Adam Knight |
|
||||