{"id":180,"date":"2010-03-07T20:53:15","date_gmt":"2010-03-08T02:53:15","guid":{"rendered":"http:\/\/www.thedarktimes.us\/wordpress\/?p=180"},"modified":"2010-03-07T20:53:15","modified_gmt":"2010-03-08T02:53:15","slug":"delete-files-older-than-x-days-on-linux","status":"publish","type":"post","link":"https:\/\/www.thedarktimes.us\/wordpress\/uncategorized\/delete-files-older-than-x-days-on-linux\/%20","title":{"rendered":"Delete Files Older Than x Days on Linux"},"content":{"rendered":"<p>Delete Files Older Than x Days on Linux<br \/>\nThe find utility on linux allows you to pass in a bunch of interesting arguments, including one to execute another command on each file. We\u2019ll use this in order to figure out what files are older than a certain number of days, and then use the rm command to delete them.<br \/>\nCommand Syntax<br \/>\nfind \/path\/to\/files* -mtime +5 -exec rm {} \\;<br \/>\nNote that there are spaces between rm, {}, and \\;<br \/>\nExplanation<br \/>\n\u2022\tThe first argument is the path to the files. This can be a path, a directory, or a wildcard as in the example above. I would recommend using the full path, and make sure that you run the command without the exec rm to make sure you are getting the right results.<br \/>\n\u2022\tThe second argument, -mtime, is used to specify the number of days old that the file is. If you enter +5, it will find files older than 5 days.<br \/>\n\u2022\tThe third argument, -exec, allows you to pass in a command such as rm. The {} \\; at the end is required to end the command.<br \/>\nThis should work on Ubuntu, Suse, Redhat, or pretty much any version of linux.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Delete Files Older Than x Days on Linux The find utility on linux allows you to pass in a bunch of interesting arguments, including one to execute another command on each file. We\u2019ll use this in order to figure out what files are older than a certain number of days, and then use the rm [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-180","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/www.thedarktimes.us\/wordpress\/wp-json\/wp\/v2\/posts\/180","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.thedarktimes.us\/wordpress\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.thedarktimes.us\/wordpress\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.thedarktimes.us\/wordpress\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.thedarktimes.us\/wordpress\/wp-json\/wp\/v2\/comments?post=180"}],"version-history":[{"count":0,"href":"https:\/\/www.thedarktimes.us\/wordpress\/wp-json\/wp\/v2\/posts\/180\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.thedarktimes.us\/wordpress\/wp-json\/wp\/v2\/media?parent=180"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.thedarktimes.us\/wordpress\/wp-json\/wp\/v2\/categories?post=180"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.thedarktimes.us\/wordpress\/wp-json\/wp\/v2\/tags?post=180"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}