{"id":65,"date":"2013-11-26T15:23:10","date_gmt":"2013-11-26T20:23:10","guid":{"rendered":"http:\/\/etapien.com\/guides\/?p=65"},"modified":"2020-08-24T14:22:37","modified_gmt":"2020-08-24T19:22:37","slug":"how-to-delete-trash-and-junk-from-a-cpanel-server","status":"publish","type":"post","link":"https:\/\/etapien.com\/guides\/how-to-delete-trash-and-junk-from-a-cpanel-server\/","title":{"rendered":"How to delete all Trash, Spam and Junk on a cPanel server"},"content":{"rendered":"<p>So here is an easy way to delete all Junk, Spam and Trash from all accounts under \/home on a cPanel server, this command will delete anything that&#8217;s older than 30 days, you can actually change that to whatever you want; you will need root access to the server.<\/p>\n<p>Let&#8217;s create a new bash script:<\/p>\n<blockquote><p>nano \/root\/delete_all_junk.sh<\/p><\/blockquote>\n<p>Now paste the following into the newly created file, and then save and exit:<\/p>\n<blockquote><p>#!\/bin\/bash<br \/>\nMAILDIRS=$(find \/home\/*\/mail\/*\/* -maxdepth 0 -type d)<br \/>\nINBOXFOLDERS=(.Trash .Junk .Spam .Low\\ Priority .cPanel\\ Reports)<br \/>\nfor basedir in $MAILDIRS; do<br \/>\nfor ((i = 0; i &lt; ${#INBOXFOLDERS[*]}; i++)); do<br \/>\nfor dir in cur new; do<br \/>\n[ -e &#8220;$basedir\/${INBOXFOLDERS[$i]}\/$dir&#8221; ] &amp;&amp; (<br \/>\necho &#8220;Processing $basedir\/${INBOXFOLDERS[$i]}\/$dir&#8230;&#8221;<br \/>\nfind &#8220;$basedir\/${INBOXFOLDERS[$i]}\/$dir\/&#8221; -type f -mtime +30 -delete<br \/>\n)<br \/>\ndone<br \/>\ndone<br \/>\ndone<br \/>\n\/scripts\/generate_maildirsize &#8211;verbose &#8211;allaccounts &#8211;force &#8211;confirm<\/p><\/blockquote>\n<p>Let&#8217;s make the newly created file executable:<\/p>\n<blockquote><p>chmod +x \/root\/delete_all_junk.sh<\/p><\/blockquote>\n<p>Then you can simply execute the file and it will do some clean up:<\/p>\n<blockquote><p>sh \/root\/delete_all_junk.sh<\/p><\/blockquote>\n<p>To change the amount of days look at the following line:<\/p>\n<blockquote><p>find &#8220;$basedir\/${INBOXFOLDERS[$i]}\/$dir\/&#8221; -type f -mtime +30 -delete<\/p><\/blockquote>\n<p>and change the 30 for something else, depending on what you want.<\/p>\n<p>This works great should you ever need to do a clean up of this sort, you can also create a cron job to clean up every once in a while and if you want to skip the trash and only delete Junk and Spam folder&#8217;s contents then just remove .Trash from the third line.<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Have you ever wanted to delete all Junk, Spam and Trash mail for all users on your cPanel server? Here is an easy way to do it.<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[7],"tags":[32,29,30,31],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v22.4 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>How to delete all Trash, Spam and Junk on a cPanel server - Tech Howtos<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/etapien.com\/guides\/how-to-delete-trash-and-junk-from-a-cpanel-server\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"How to delete all Trash, Spam and Junk on a cPanel server - Tech Howtos\" \/>\n<meta property=\"og:description\" content=\"Have you ever wanted to delete all Junk, Spam and Trash mail for all users on your cPanel server? Here is an easy way to do it.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/etapien.com\/guides\/how-to-delete-trash-and-junk-from-a-cpanel-server\/\" \/>\n<meta property=\"og:site_name\" content=\"Tech Howtos\" \/>\n<meta property=\"article:published_time\" content=\"2013-11-26T20:23:10+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2020-08-24T19:22:37+00:00\" \/>\n<meta name=\"author\" content=\"Etapien\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Etapien\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"1 minute\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/etapien.com\/guides\/how-to-delete-trash-and-junk-from-a-cpanel-server\/\",\"url\":\"https:\/\/etapien.com\/guides\/how-to-delete-trash-and-junk-from-a-cpanel-server\/\",\"name\":\"How to delete all Trash, Spam and Junk on a cPanel server - Tech Howtos\",\"isPartOf\":{\"@id\":\"https:\/\/etapien.com\/guides\/#website\"},\"datePublished\":\"2013-11-26T20:23:10+00:00\",\"dateModified\":\"2020-08-24T19:22:37+00:00\",\"author\":{\"@id\":\"https:\/\/etapien.com\/guides\/#\/schema\/person\/c67f514649b78dbb5ef0c254a0521424\"},\"breadcrumb\":{\"@id\":\"https:\/\/etapien.com\/guides\/how-to-delete-trash-and-junk-from-a-cpanel-server\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/etapien.com\/guides\/how-to-delete-trash-and-junk-from-a-cpanel-server\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/etapien.com\/guides\/how-to-delete-trash-and-junk-from-a-cpanel-server\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/etapien.com\/guides\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"How to delete all Trash, Spam and Junk on a cPanel server\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/etapien.com\/guides\/#website\",\"url\":\"https:\/\/etapien.com\/guides\/\",\"name\":\"Tech Howtos\",\"description\":\"Tech related useful howtos\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/etapien.com\/guides\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/etapien.com\/guides\/#\/schema\/person\/c67f514649b78dbb5ef0c254a0521424\",\"name\":\"Etapien\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/etapien.com\/guides\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/55021fd8fb4a829ad64ffab0a92d3b90?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/55021fd8fb4a829ad64ffab0a92d3b90?s=96&d=mm&r=g\",\"caption\":\"Etapien\"},\"url\":\"https:\/\/etapien.com\/guides\/author\/Etapien\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"How to delete all Trash, Spam and Junk on a cPanel server - Tech Howtos","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/etapien.com\/guides\/how-to-delete-trash-and-junk-from-a-cpanel-server\/","og_locale":"en_US","og_type":"article","og_title":"How to delete all Trash, Spam and Junk on a cPanel server - Tech Howtos","og_description":"Have you ever wanted to delete all Junk, Spam and Trash mail for all users on your cPanel server? Here is an easy way to do it.","og_url":"https:\/\/etapien.com\/guides\/how-to-delete-trash-and-junk-from-a-cpanel-server\/","og_site_name":"Tech Howtos","article_published_time":"2013-11-26T20:23:10+00:00","article_modified_time":"2020-08-24T19:22:37+00:00","author":"Etapien","twitter_misc":{"Written by":"Etapien","Est. reading time":"1 minute"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/etapien.com\/guides\/how-to-delete-trash-and-junk-from-a-cpanel-server\/","url":"https:\/\/etapien.com\/guides\/how-to-delete-trash-and-junk-from-a-cpanel-server\/","name":"How to delete all Trash, Spam and Junk on a cPanel server - Tech Howtos","isPartOf":{"@id":"https:\/\/etapien.com\/guides\/#website"},"datePublished":"2013-11-26T20:23:10+00:00","dateModified":"2020-08-24T19:22:37+00:00","author":{"@id":"https:\/\/etapien.com\/guides\/#\/schema\/person\/c67f514649b78dbb5ef0c254a0521424"},"breadcrumb":{"@id":"https:\/\/etapien.com\/guides\/how-to-delete-trash-and-junk-from-a-cpanel-server\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/etapien.com\/guides\/how-to-delete-trash-and-junk-from-a-cpanel-server\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/etapien.com\/guides\/how-to-delete-trash-and-junk-from-a-cpanel-server\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/etapien.com\/guides\/"},{"@type":"ListItem","position":2,"name":"How to delete all Trash, Spam and Junk on a cPanel server"}]},{"@type":"WebSite","@id":"https:\/\/etapien.com\/guides\/#website","url":"https:\/\/etapien.com\/guides\/","name":"Tech Howtos","description":"Tech related useful howtos","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/etapien.com\/guides\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/etapien.com\/guides\/#\/schema\/person\/c67f514649b78dbb5ef0c254a0521424","name":"Etapien","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/etapien.com\/guides\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/55021fd8fb4a829ad64ffab0a92d3b90?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/55021fd8fb4a829ad64ffab0a92d3b90?s=96&d=mm&r=g","caption":"Etapien"},"url":"https:\/\/etapien.com\/guides\/author\/Etapien\/"}]}},"_links":{"self":[{"href":"https:\/\/etapien.com\/guides\/wp-json\/wp\/v2\/posts\/65"}],"collection":[{"href":"https:\/\/etapien.com\/guides\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/etapien.com\/guides\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/etapien.com\/guides\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/etapien.com\/guides\/wp-json\/wp\/v2\/comments?post=65"}],"version-history":[{"count":7,"href":"https:\/\/etapien.com\/guides\/wp-json\/wp\/v2\/posts\/65\/revisions"}],"predecessor-version":[{"id":73,"href":"https:\/\/etapien.com\/guides\/wp-json\/wp\/v2\/posts\/65\/revisions\/73"}],"wp:attachment":[{"href":"https:\/\/etapien.com\/guides\/wp-json\/wp\/v2\/media?parent=65"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/etapien.com\/guides\/wp-json\/wp\/v2\/categories?post=65"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/etapien.com\/guides\/wp-json\/wp\/v2\/tags?post=65"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}