Disk space
Isolating what files or directories are consuming the most space is crucial when troubleshooting disk utilization problems. The du command with the -kx options is the ideal tool for this job. The k option is for displaying block counts in 1024-byte (1-Kbyte) blocks. I prefer kilobytes because it sorts better than gigabytes. The x option is so file system mount points are not traversed. You don’t want to waste time searching a large 10TB NFS mount point when you are only concerned about the 20GB local file system.
~$ sudo du -kx / | sort -nr | more
2810724 /
1552048 /var
896116 /usr
653656 /var/www
471572 /var/lib
437180 /var/www/wordpress
418432 /var/www/wordpress/wp-content
382020 /var/www/wordpress/wp-content/themes
355004 /usr/lib
248892 /var/lib/varnish
230000 /usr/share
210928 /var/cache
208544 /var/log
186272 /var/www/wordpress/wp-content/themes/tiny-forge
186080 /home
Once you find the directory that is consuming the most space you can run the following one liner to compress any log file that is older than 7 days. (Assuming it’s log files.) Ideally log files should be put under a log rotation schedule via logrotate. Run the following command from within the directory that contains the log files.
find . -type f -name "*.log" -mtime +7 -print -exec gzip {} \;
Additionally if you don’t need the log files, then you can simply delete them instead of compressing them.
find . -type f -name "*.log" -mtime +7 -print -exec rm -fr {} \;
Tagged With: Linux du disk space
Facebook Comments