Saturday, August 14, 2010

Delete old log files in Linux

Here is the quick command to delete the log files which are older than specified time in Linux

Be careful as these are powerful commands which blow away files completely.
  

Note: 
To find files modified more than 5 days use -mtime +5 and files modified less than 5 days use -mtime -5

Use -ctime parameter to find out the created time

To List and Delete log files older than 10 days, execute the following commands
 

find /var/log/ -name *.log -mtime +10 -exec ls -tl {} \; 
find /var/log/ -name *.log -mtime +10 -exec rm -f {} \;

By Suresh : rm -rf *.[0-9]