Today I encountered an issue that required the use of one such program. The issue was, however, that the server in question was headless running as a VM with no GUI access. I learned about du.
The issue showed that the sda3 device was 95% percent full. It is a 2G partition for storing logs. When wiping logs didnt resolve the issue I was faced with needing to figure out where 1.7 or so GB was going. I looked around and saw this little command.
$ du -h --max-depth 1
This command, like df (which shows your mounted volumes) takes the -h flag to show human readable output sizes (not just as bytes, but 2.4G or 8.0K abbreviations). The --max-depth 1 command tells it do go down 1 directory in size scale.
So looking in the home folder of my home server, running the above command will tell me the sizes of all of my directories within the home directory, then at the bottom, give a total size of home as the directory '.' If that is the only thing you care about, the total size of everything in your working directory, do --max-depth 0.
This can even dig deeper with more depth sizes to show where the file size hog is if you don't want to manually drill down. The only thing I have yet to figure out is how to sort the output by size so the culprit is made immediately known.
In the case of the server this morning, there was an error log that managed to fill the entire directory with the same line.
update:
if you pipe the above command into sort -h it should sort by size
so:
$ du -h --max-depth 1 | sort -h | more
Would show file sizes of directories, sort by size and step page-by-page (the more command)
No comments:
Post a Comment