I've noticed that one of our interface directories has a lot of old files, some of them were more than a year old. I checked it with our implementers and it turns out that we can delete all files that are older than 60 days. I decided to write a (tiny) shell script to purge all files older than 60 days and schedule it with crontab, this way I won't deal with it manually. I wrote a find command to identify and delete those files. I started with the following command:
It finds and deletes all files in directory /interface/inbound that are older than 60 days. After packing it in a shell script I got a request to delete "csv" files only. No problem... I added the "-name" to the find command:
All csv files in /interface/inbound that are older than 60 days will be deleted. But then, the request had changed, and I was asked to delete "*.xls" files further to "*.csv" files. At this point things went complicated for me since I'm not a shell script expert... I tried several things, like add another "-name" to the find command:
But no file was deleted. Couple of moments later I understood that I'm trying to find csv files which is also xls files... (logically incorrect of course). After struggling a liitle with the find command, I managed to make it works:
:-) Aviad |
Wednesday, June 10, 2009
Purge old files on Linux/Unix using “find” command
Posted by Aviad at 9:30 AM 7 comments
Labels: Unix\Linux
Subscribe to:
Posts (Atom)