It's important to do spring cleaning every once in a while and ensure automated processes.
If your tmp dir is not getting cleared:
- yum install tmpwatch – removes files older than 10 days.
- /var/log has a ton of logs, they should all be setup on logrotate (if they are not use some of the commands below to find out what is getting out of hand
- Pay attention to config files that create logs in strange places outside of the common var/log path (likely because you set it up that way). eg, check your log paths for apache, nignx etc. Then custom configure a log rotation for it.
Generic command to find the top 50 files on your entire server
- find / -type f -printf ‘%k kb %p\n’| sort -nr | head -50
Use the find command to list *.sql specific files within the root folder and show the top 50.
- find /root/ -type f -name \*.sql -printf ‘%k kb %p\n’| sort -nr | head -50
Same thing but using the DU function which doesn’t have as nice of a printout.
- du -h /home | sort -n -r | head -n 50
Or you could just go around using this command. Start from root, change depth as necessary, and then CD into each directory you find suspiciously large.
- du -h –max-depth=1
This will output the usage of each partition in the server. To list the size of a specific directory, run the following command:
- # du -sh /home/
If you want to list all the subdirectory sizes under /home, run the following command:
- # du -sh /home/*
Top X files in a dirtory that are larger than 10 MB, sorted by size
- find . -maxdepth 1 -type f -size +10M -print0 | xargs -0 ls -Shal | head
Note, the find commands could take a while…
Entrupeners, Subscribe for the lastest tools, tips, and tutorials.