I have a directory and I want to log, from now on, its size every day. That is, at some time of day, every day, I want to compute the size of this directory, and append it in some file along with the date.
NOTE: By size of the directory I mean the size of the all the contents, recursively.
What's the recommended way of doing this?
Best Answer
You could run something
du
from a cron job. With GNU tools,du -sb dir/
would give you the size in bytes of the directory and all files within it, recursively (plus the directory name, but we can remove that). And you can get the date withdate
. E.g.Then put that in a cron job and direct the output to a file. A crontab entry to run at 06:00 every day could be something like this (of course, I'm only using
/tmp
here as just an example):The percent signs need to be escaped for
cron
.You could use
du -sk
for kilobytes, ordu -sh
for "human-readable" auto-scaling output. The options accepted bydu
may be different on another system.Use something like
du ... | sed -e 's/[[:blank:]].*//'
instead, if you want to remove the pathname thatdu
prints.