Linux – How to track growing directories

bashlinuxscriptingshellunix

I have a system that continually runs out of disk space. Im going to write a script that cleans up directories that grow larger. Usually these are log directories. Given the nature of the machine, i dont need to keep logs.

I want to write a script that shows me all the directories that are increasing in size, so i can make sure this list goes to 0.

I am thinking something like this

1. du /
2. wait 24 hrs
3. du /
4. find all instances where the file size increased

It looks simple enough, but my issue is that du works on files and directories, you cant do it on only dirs. How can i overcome that?

Best Answer

You could use find to tell whats been modified in 24 hours,

find / -type d name \* -mtime 1 -print

Should list all directories that have changed in the last 24 hours, but remember, realistically its files that change rather than the directories.

Another way would be to do

du -s *  | sort > currentsize

This summerises by directory, and files in the starting location, but, you then could store it each day, move that file to say oldsize, run the command again

then

diff currentsize oldsize

you can see whats changed.

You could use awk to decide if one is bigger or smaller..

All system logs tend to to change too.

But the original find I stated shows you files altered in the last 24 hours. You could also use something based on that.