I have a requirement where I have to find some core/log files which are growing continuously and eating up my disk space in one of the production server. Now my job is to find them and delete some of them which are not required. For this we have to follow below procedure to get the files which are growing now.
Logic : We will create a empty file using touch command. We will use find command to see all the files which are newer than file which we just created and then delete the files which are not required much.
Step1 : Create an empty file in any location, but prefered location is your home directory
#touch /root/testfile
Step2 : Find all the files which are newer than this file
#find / -newer /root/testfile -exec ls -lh {} ;
The above command will search entire server(/) for newer files(-newer) which are created/accessed after /root/testfile then list(ls -lh) in human readable.
For more meaning fullness you can exclude some of the system folders such as proc as shown below
find / ( -name proc -prune ) -o -newer /root/testfile -exec ls -lh {} ;
Even more meaning full way. As the file is still growing in size you can filter it out using -size command. Suppose you want to list all the growing files which are more then some size(Here in my example it’s 300KB) you can use below command which will list files which are growing and whose size is more than 300KB.
find / ( -name proc -prune ) -o -newer test -size +300k -exec ls -lh {} ;
Once you find the files you can delete or move to other server where you have more space.
Latest posts by Surendra Anne (see all)
- Docker: How to copy files to/from docker container - June 30, 2020
- Anisble: ERROR! unexpected parameter type in action:
Fix - June 29, 2020 - FREE: JOIN OUR DEVOPS TELEGRAM GROUPS - August 2, 2019
- Review: Whizlabs Practice Tests for AWS Certified Solutions Architect Professional (CSAP) - August 27, 2018
- How to use ohai/chef-shell to get node attributes - July 19, 2018