Track size of a directory over time
Clash Royale CLAN TAG#URR8PPP
up vote
4
down vote
favorite
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?
logs directory size
add a comment |Â
up vote
4
down vote
favorite
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?
logs directory size
add a comment |Â
up vote
4
down vote
favorite
up vote
4
down vote
favorite
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?
logs directory size
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?
logs directory size
edited Jul 3 at 16:41
Jeff Schaller
30.8k846104
30.8k846104
asked Jul 3 at 12:19
becko
5142716
5142716
add a comment |Â
add a comment |Â
1 Answer
1
active
oldest
votes
up vote
8
down vote
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 with date
. E.g.
$ printf "$(date +"%F %T") $(du -sb /tmp)n"
2018-07-03 15:25:57 24246930 /tmp
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):
0 6 * * * printf "$(date +"%F %T") $(du -sb /tmp)n" >> /tmp/tmp-size.log
The percent signs need to be escaped for cron
.
You could use du -sk
for kilobytes, or du -sh
for "human-readable" auto-scaling output. The options accepted by du
may be different on another system.
Use something like du ... | sed -e 's/[[:blank:]].*//'
instead, if you want to remove the pathname that du
prints.
1
Good solution. You might want to add this in the crontab of root user to avoid potential permission issuesdu: cannot read directory /tmp/systemd-private-...: Permission denied
â Kevin Lemaire
Jul 3 at 12:37
add a comment |Â
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
8
down vote
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 with date
. E.g.
$ printf "$(date +"%F %T") $(du -sb /tmp)n"
2018-07-03 15:25:57 24246930 /tmp
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):
0 6 * * * printf "$(date +"%F %T") $(du -sb /tmp)n" >> /tmp/tmp-size.log
The percent signs need to be escaped for cron
.
You could use du -sk
for kilobytes, or du -sh
for "human-readable" auto-scaling output. The options accepted by du
may be different on another system.
Use something like du ... | sed -e 's/[[:blank:]].*//'
instead, if you want to remove the pathname that du
prints.
1
Good solution. You might want to add this in the crontab of root user to avoid potential permission issuesdu: cannot read directory /tmp/systemd-private-...: Permission denied
â Kevin Lemaire
Jul 3 at 12:37
add a comment |Â
up vote
8
down vote
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 with date
. E.g.
$ printf "$(date +"%F %T") $(du -sb /tmp)n"
2018-07-03 15:25:57 24246930 /tmp
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):
0 6 * * * printf "$(date +"%F %T") $(du -sb /tmp)n" >> /tmp/tmp-size.log
The percent signs need to be escaped for cron
.
You could use du -sk
for kilobytes, or du -sh
for "human-readable" auto-scaling output. The options accepted by du
may be different on another system.
Use something like du ... | sed -e 's/[[:blank:]].*//'
instead, if you want to remove the pathname that du
prints.
1
Good solution. You might want to add this in the crontab of root user to avoid potential permission issuesdu: cannot read directory /tmp/systemd-private-...: Permission denied
â Kevin Lemaire
Jul 3 at 12:37
add a comment |Â
up vote
8
down vote
up vote
8
down vote
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 with date
. E.g.
$ printf "$(date +"%F %T") $(du -sb /tmp)n"
2018-07-03 15:25:57 24246930 /tmp
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):
0 6 * * * printf "$(date +"%F %T") $(du -sb /tmp)n" >> /tmp/tmp-size.log
The percent signs need to be escaped for cron
.
You could use du -sk
for kilobytes, or du -sh
for "human-readable" auto-scaling output. The options accepted by du
may be different on another system.
Use something like du ... | sed -e 's/[[:blank:]].*//'
instead, if you want to remove the pathname that du
prints.
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 with date
. E.g.
$ printf "$(date +"%F %T") $(du -sb /tmp)n"
2018-07-03 15:25:57 24246930 /tmp
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):
0 6 * * * printf "$(date +"%F %T") $(du -sb /tmp)n" >> /tmp/tmp-size.log
The percent signs need to be escaped for cron
.
You could use du -sk
for kilobytes, or du -sh
for "human-readable" auto-scaling output. The options accepted by du
may be different on another system.
Use something like du ... | sed -e 's/[[:blank:]].*//'
instead, if you want to remove the pathname that du
prints.
edited Jul 3 at 12:55
answered Jul 3 at 12:27
ilkkachu
47.3k668130
47.3k668130
1
Good solution. You might want to add this in the crontab of root user to avoid potential permission issuesdu: cannot read directory /tmp/systemd-private-...: Permission denied
â Kevin Lemaire
Jul 3 at 12:37
add a comment |Â
1
Good solution. You might want to add this in the crontab of root user to avoid potential permission issuesdu: cannot read directory /tmp/systemd-private-...: Permission denied
â Kevin Lemaire
Jul 3 at 12:37
1
1
Good solution. You might want to add this in the crontab of root user to avoid potential permission issues
du: cannot read directory /tmp/systemd-private-...: Permission denied
â Kevin Lemaire
Jul 3 at 12:37
Good solution. You might want to add this in the crontab of root user to avoid potential permission issues
du: cannot read directory /tmp/systemd-private-...: Permission denied
â Kevin Lemaire
Jul 3 at 12:37
add a comment |Â
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f453212%2ftrack-size-of-a-directory-over-time%23new-answer', 'question_page');
);
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password