{"id":4140,"date":"2025-06-08T12:10:56","date_gmt":"2025-06-08T12:10:56","guid":{"rendered":"https:\/\/w3buddy.com\/?post_type=cposts&#038;p=4140"},"modified":"2025-06-08T12:10:57","modified_gmt":"2025-06-08T12:10:57","slug":"file-system-housekeeping-with-find-command","status":"publish","type":"cposts","link":"https:\/\/w3buddy.com\/blog\/notes\/oracle-dba-d2d-tasks\/file-system-housekeeping-with-find-command\/","title":{"rendered":"File System Housekeeping with find Command"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">A tidy filesystem is key to a healthy and efficient server. The <code>find<\/code> command is a powerful tool for cleaning, compressing, or inspecting files based on name, size, or modification time. Use this guide to manage trace logs, old backups, and large junk files like a pro.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Basic Syntax<\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code><code>find &#91;path] &#91;conditions] &#91;actions]<\/code><\/code><\/pre>\n\n\n\n<ul class=\"wp-block-list\">\n<li><code>path<\/code>: Where to begin the search (<code>.<\/code> for current dir, or <code>\/u01\/app\/logs<\/code> for specific)<\/li>\n\n\n\n<li><code>conditions<\/code>: Filters like <code>-name<\/code>, <code>-mtime<\/code>, <code>-size<\/code><\/li>\n\n\n\n<li><code>actions<\/code>: What to do: <code>-exec<\/code>, <code>-print<\/code>, <code>-delete<\/code>, etc.<\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\">Common Examples<\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code><code># 1. Delete .trc files older than 1 day\nfind . -name \"*.trc\" -type f -mtime +1 -exec rm {} \\;\n\n# 2. Compress .log files older than 10 days\nfind . -name \"*.log\" -type f -mtime +10 -exec gzip {} \\;\n\n# 3. Delete empty files (size 0)\nfind . -type f -size 0 -exec rm {} \\;\n\n# 4. Compress files larger than 10MB\nfind . -type f -size +10M -exec gzip {} \\;\n\n# 5. Find files modified in the last 5 days\nfind . -type f -mtime -5 -print\n\n# 6. Delete .arc files older than 30 days in a specific directory\nfind \/path\/to\/directory -name \"*.arc\" -type f -mtime +30 -exec rm {} \\;\n\n# 7. Find &amp; print 5 largest files modified in the last day\nfind . -type f -mtime -1 -printf \"%p %s\\n\" | sort -k2nr | head -5\n\n# 8. Delete all .gz files older than 7 days\nfind . -name \"*.gz\" -type f -mtime +7 -exec rm {} \\;\n\n# 9. Compress .trm files older than 0 days (today's)\nfind . -name \"*.trm\" -type f -mtime +0 -exec gzip {} \\;\n\n# 10. Delete files larger than 100MB\nfind . -type f -size +100M -exec rm {} \\;<\/code><\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">\ud83d\udccc Notes<\/h3>\n\n\n\n<ul class=\"wp-block-list\">\n<li><code>-mtime +N<\/code>: Modified <em>more than<\/em> N days ago<\/li>\n\n\n\n<li><code>-mtime -N<\/code>: Modified <em>within<\/em> the last N days<\/li>\n\n\n\n<li><code>-exec ... {} \\;<\/code>: Executes a command on each result<\/li>\n\n\n\n<li>Always test with <code>-print<\/code> before <code>-exec rm<\/code> to avoid accidental deletions<\/li>\n\n\n\n<li>Use cron to automate regular cleanups<\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"<p>A tidy filesystem is key to a healthy and efficient server. The find command is a powerful tool for cleaning, compressing, or inspecting files based on name, size, or modification time. Use this guide to manage trace logs, old backups, and large junk files like a pro. Basic Syntax Common Examples \ud83d\udccc Notes<\/p>\n","protected":false},"template":"","meta":{"googlesitekit_rrm_CAowu461DA:productID":""},"categories":[952,984],"class_list":["post-4140","cposts","type-cposts","status-publish","hentry","category-notes","category-oracle-dba-d2d-tasks"],"_links":{"self":[{"href":"https:\/\/w3buddy.com\/blog\/wp-json\/wp\/v2\/cposts\/4140","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/w3buddy.com\/blog\/wp-json\/wp\/v2\/cposts"}],"about":[{"href":"https:\/\/w3buddy.com\/blog\/wp-json\/wp\/v2\/types\/cposts"}],"wp:attachment":[{"href":"https:\/\/w3buddy.com\/blog\/wp-json\/wp\/v2\/media?parent=4140"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/w3buddy.com\/blog\/wp-json\/wp\/v2\/categories?post=4140"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}