Friday, March 22, 2013

Script for finding and removing old data + UNIX

Hi Friends,

In day to day job of Unix Admin, we need to remove old data which is not required or not being accessed for more than ten days, twenty days or a month or some times a year.

this is applicable for any UNIX platform. we can use find command and very much use the manual of the same. It is very useful command, which can be used to find data located at any place in the desired directory or internal directories.

before using remove command, we can use list command to check whether the command is working properly or as desired or not.


#find /var/log/ -type f -atime +10 -exec ls -ltr {} \;

 
now if this command is useful and working fine for you then use rm i.e. remove command to remove the content.
 

find /var/log -type f -atime +10 -exec rm -rf {} \;

in my case data listed and then removed is set for 10 days i.e. the data which is not being accessed for more than ten days will be listed or removed respectively.
 
Thanks & Regards
Love Sharing
Amit Chopra

No comments: