Purge old files on Linux/Unix using “find” command
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: find /interfaces/inbound -mtime +60 -type f -maxdepth 1 -exec rm {} \; It finds and deletes all files in directory /interface/inbound that are older than 60 days. "-maxdepth 1" -> find files in current directory only. Don't look for files in sub directories. 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: find /interfaces/inbound -name "*.csv" -mtime +60 -type f -maxdepth 1 -exec rm {} \; 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: find /interfaces/inbound -name "*.csv" -name "*.xls" -mtime +60 -type f -maxdepth 1 -exec rm {} \; 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: find /interfaces/inbound \( -name "*.csv" -o -name "*.xls" \) -mtime +60 -type f -maxdepth 1 -exec rm {} \;
Posted by Mohammed Sajid Siddique at 8:50 AM 0 comments
Subscribe to: Posts (Atom)
Oracle E-Business Suite 11i Certified Professional & Expert
Oracle E-Business Suite 11i Certified Professional Supply Chain ConsultantOracle E-Business Suite 11i Certified Professional Financial ConsultantOracle E-Business Suite 11i Applications Database Administrator Certified ProfessionalOracle E-Business Suite 11i Application System Administrator Certified ExpertOracle E-Business Suite 11i Workflow Certified Expert
Oracle 9i, 10g DBA Certified Professional
Oracle 11i Apps DBA Certified Professional
Oracle 10g RAC Certified Expert
Check My LinkedIn Profile
Followers
if (!window.google !google.friendconnect) {
document.write('' +
'');
}
if (!window.registeredBloggerCallbacks) {
window.registeredBloggerCallbacks = true;
var registeredGadgets = [];
gadgets.rpc.register('registerGadgetForRpcs', function(gadgetDomain, iframeName) {
// Trim the gadget domain from a random url (w/ query params)
// down to just a top level domain.
var startIndex = 0;
var protocolMarker = "://";
// Find the start of the host name
if (gadgetDomain.indexOf(protocolMarker) != -1) {
startIndex = gadgetDomain.indexOf(protocolMarker) + protocolMarker.length;
}
// Now find the start of the path
var pathIndex = gadgetDomain.indexOf("/", startIndex);
// Now extract just the hostname
if (pathIndex != -1) {
gadgetDomain = gadgetDomain.substring(0, pathIndex);
}
gadgets.rpc.setRelayUrl(iframeName, gadgetDomain + "/ps/rpc_relay.html");
// Just return some random stuff so the gadget can tell when
// we're done.
return "callback";
});
gadgets.rpc.register('getBlogUrls', function() {
var holder = {};
holder.postFeed = "http://www.blogger.com/feeds/8358218337220897152/posts/default";
holder.commentFeed = "http://www.blogger.com/feeds/8358218337220897152/comments/default";
return holder;
});
gadgets.rpc.register('requestReload', function() {
document.location.reload();
});
gadgets.rpc.register('requestSignOut', function(siteId) {
google.friendconnect.container.openSocialSiteId = siteId;
google.friendconnect.requestSignOut();
});
}
var skin = {};
skin['FACE_SIZE'] = '32';
skin['HEIGHT'] = "260";
skin['TITLE'] = "Followers";
skin['BORDER_COLOR'] = "transparent";
skin['ENDCAP_BG_COLOR'] = "transparent";
skin['ENDCAP_TEXT_COLOR'] = "#335566";
skin['ENDCAP_LINK_COLOR'] = "#336699";
skin['ALTERNATE_BG_COLOR'] = "transparent";
skin['CONTENT_BG_COLOR'] = "transparent";
skin['CONTENT_LINK_COLOR'] = "#336699";
skin['CONTENT_TEXT_COLOR'] = "#335566";
skin['CONTENT_SECONDARY_LINK_COLOR'] = "#336699";
skin['CONTENT_SECONDARY_TEXT_COLOR'] = "#000000";
skin['CONTENT_HEADLINE_COLOR'] = "#000000";
skin['FONT_FACE'] = "normal normal 100% Helvetica, Arial, sans-serif";
google.friendconnect.container.setParentUrl("/");
google.friendconnect.container["renderMembersGadget"](
{id: "div-12lb4ztjxsrx2",
height: 260,
site: "18212234755094357901",
useLightBoxForCanvas: false,
locale: 'en' },
skin);
Thursday, October 8, 2009
Purge old files on Linux/Unix using “find” command
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment