{"id":6849,"date":"2025-02-05T00:36:23","date_gmt":"2025-02-04T19:06:23","guid":{"rendered":"https:\/\/www.veeble.com\/kb\/?p=6849"},"modified":"2025-04-30T12:22:18","modified_gmt":"2025-04-30T06:52:18","slug":"how-to-delete-files-older-than-30-days-in-linux","status":"publish","type":"post","link":"https:\/\/www.veeble.com\/kb\/how-to-delete-files-older-than-30-days-in-linux\/","title":{"rendered":"How to Delete Files Older Than 30 Days in Linux Easily?"},"content":{"rendered":"\n<p><strong><span style=\"text-decoration: underline\">Delete Files Older Than 30 Days in Linux? &#8211; Here&#8217;s How!<\/span><\/strong><br>As time passes, your Linux system collects various files like logs, backups, and temporary data, which can take up important disk space. Removing these outdated files is essential to keep your system running smoothly and avoid storage problems. In this guide, we will discuss how to delete files older than a certain number of days or older than 30 days, ways to automate this process, and some best practices to follow using the <mark style=\"background-color:#f8f1a1\" class=\"has-inline-color\"><strong>find command<\/strong>, <strong>bash script<\/strong>, <strong>cron job,<\/strong> and <strong>tmpwatch command<\/strong>.<\/mark><\/p>\n\n\n\n<p><strong>Before diving into commands, here\u2019s a simple flowchart to help you decide the best method for your needs:<\/strong><\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><a href=\"https:\/\/www.veeble.com\/kb\/wp-content\/uploads\/2025\/02\/A4166CF0-1CF3-47E4-B09D-AD3C2AAA9DE8.png\"><img loading=\"lazy\" decoding=\"async\" width=\"2073\" height=\"519\" src=\"https:\/\/www.veeble.com\/kb\/wp-content\/uploads\/2025\/02\/A4166CF0-1CF3-47E4-B09D-AD3C2AAA9DE8.png\" alt=\"Do you want to delete files manually? then use find command. \nDo you want to automatically delete and want a one-time cleanup? then use find command with cron job. If you need a recurring cleanup for automatical deletion, then use tmpwatch or a bash script with cron job.. here tmpwatch is useful for temp files where as bash script with cron job can be widely used for any type of files!\n\nBy opting the correct command from this chart, you can find out how to delete files older than 30 days in linux\" class=\"wp-image-6864\" srcset=\"https:\/\/www.veeble.com\/kb\/wp-content\/uploads\/2025\/02\/A4166CF0-1CF3-47E4-B09D-AD3C2AAA9DE8.png 2073w, https:\/\/www.veeble.com\/kb\/wp-content\/uploads\/2025\/02\/A4166CF0-1CF3-47E4-B09D-AD3C2AAA9DE8-300x75.png 300w, https:\/\/www.veeble.com\/kb\/wp-content\/uploads\/2025\/02\/A4166CF0-1CF3-47E4-B09D-AD3C2AAA9DE8-1024x256.png 1024w, https:\/\/www.veeble.com\/kb\/wp-content\/uploads\/2025\/02\/A4166CF0-1CF3-47E4-B09D-AD3C2AAA9DE8-768x192.png 768w, https:\/\/www.veeble.com\/kb\/wp-content\/uploads\/2025\/02\/A4166CF0-1CF3-47E4-B09D-AD3C2AAA9DE8-1536x385.png 1536w, https:\/\/www.veeble.com\/kb\/wp-content\/uploads\/2025\/02\/A4166CF0-1CF3-47E4-B09D-AD3C2AAA9DE8-2048x513.png 2048w\" sizes=\"auto, (max-width: 2073px) 100vw, 2073px\" \/><\/a><\/figure>\n\n\n\t\t\t\t<div class=\"wp-block-uagb-table-of-contents uagb-toc__align-left uagb-toc__columns-1  uagb-block-43565f70      \"\n\t\t\t\t\tdata-scroll= \"1\"\n\t\t\t\t\tdata-offset= \"30\"\n\t\t\t\t\tstyle=\"\"\n\t\t\t\t>\n\t\t\t\t<div class=\"uagb-toc__wrap\">\n\t\t\t\t\t\t<div class=\"uagb-toc__title\">\n\t\t\t\t\t\t\tTable of Contents\t\t\t\t\t\t<\/div>\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t<div class=\"uagb-toc__list-wrap \">\n\t\t\t\t\t\t<ol class=\"uagb-toc__list\"><li class=\"uagb-toc__list\"><a href=\"#manual-file-deletion\" class=\"uagb-toc-link__trigger\">Manual File Deletion<\/a><ul class=\"uagb-toc__list\"><li class=\"uagb-toc__list\"><a href=\"#delete-old-files-using-the-find-command\" class=\"uagb-toc-link__trigger\">Delete Old Files Using the Find Command<\/a><\/li><\/ul><\/li><li class=\"uagb-toc__list\"><a href=\"#automating-file-deletion\" class=\"uagb-toc-link__trigger\">Automating File Deletion<\/a><ul class=\"uagb-toc__list\"><li class=\"uagb-toc__list\"><a href=\"#deletion-of-files-using-cron-job-and-find-command\" class=\"uagb-toc-link__trigger\">Deletion of Files using Cron Job and Find Command<\/a><\/li><\/ul><\/li><\/ul><li class=\"uagb-toc__list\"><a href=\"#continuous-automatic-cleanup-of-old-files\" class=\"uagb-toc-link__trigger\">Continuous Automatic Cleanup of Old Files<\/a><ul class=\"uagb-toc__list\"><li class=\"uagb-toc__list\"><a href=\"#automatic-cleanup-of-temporary-files-with-tmpwatch-command\" class=\"uagb-toc-link__trigger\">Automatic Cleanup of Temporary Files with tmpwatch Command<\/a><li class=\"uagb-toc__list\"><li class=\"uagb-toc__list\"><a href=\"#automatic-deletion-of-old-regular-files-using-bash-script-with-find\" class=\"uagb-toc-link__trigger\">Automatic Deletion of Old Regular Files using Bash Script with Find<\/a><\/li><\/ul><li class=\"uagb-toc__list\"><a href=\"#unlimited-bandwidth-windows-hosting\" class=\"uagb-toc-link__trigger\">Unlimited Bandwidth Windows Hosting<\/a><\/ol>\t\t\t\t\t<\/div>\n\t\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\n\n\n<p><\/p>\n\n\n<h2 class=\"wp-block-heading has-text-align-center\" id=\"manual-file-deletion\"><span style=\"text-decoration: underline\"><strong>Manual File Deletion<\/strong><\/span><\/h2>\n\n<h4 class=\"wp-block-heading has-text-align-center\" id=\"delete-old-files-using-the-find-command\">Delete Old Files Using the Find Command<\/h4>\n\n\n<p>The most efficient way to remove old files manually in Linux is with the <a href=\"https:\/\/www.veeble.com\/kb\/how-to-find-files-containing-specific-text-in-linux\/\">find command<\/a>. <br>Here\u2019s a simple example:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>find \/path\/to\/directory -type f -mtime +30 -exec rm -f {} \\;<\/code><\/pre>\n\n\n\n<figure class=\"wp-block-table is-style-stripes has-small-font-size\"><table><thead><tr><th class=\"has-text-align-center\" data-align=\"center\">Options<\/th><th>Description<\/th><\/tr><\/thead><tbody><tr><td class=\"has-text-align-center\" data-align=\"center\">\/path\/to\/directory<\/td><td>The directory where the search begins. Replace this with the actual path.<\/td><\/tr><tr><td class=\"has-text-align-center\" data-align=\"center\">-type f<\/td><td>Searches only for files (ignores directories).<\/td><\/tr><tr><td class=\"has-text-align-center\" data-align=\"center\">-mtime +30<\/td><td>Finds files modified more than 30 days ago.<\/td><\/tr><tr><td class=\"has-text-align-center\" data-align=\"center\">-exec rm -f {} \\;<\/td><td>Deletes each file found (<code>rm -f<\/code> forces deletion).<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p>This command removes files that are older than 30 days via the Linux command line after the command is executed by the user.<\/p>\n\n\n<h6 class=\"wp-block-heading\" id=\"examples\"><strong>Examples:<\/strong><\/h6>\n\n\n<ul class=\"wp-block-list\">\n<li>Delete files older than <strong>7 days<\/strong>: <code>find \/var\/log -type f -mtime +7 -exec rm -f {} \\;<\/code><\/li>\n\n\n\n<li>Delete files older than <strong>60 days<\/strong>: <code>find \/backup -type f -mtime +60 -exec rm -f {} \\;<\/code><\/li>\n\n\n\n<li>Delete files older than <strong>90 days<\/strong>: <code>find \/tmp -type f -mtime +90 -exec rm -f {} \\;<\/code><\/li>\n<\/ul>\n\n\n\n<figure class=\"wp-block-image size-full\"><a href=\"https:\/\/www.veeble.com\/kb\/wp-content\/uploads\/2025\/02\/Screenshot-from-2025-02-04-12-15-46.png\"><img loading=\"lazy\" decoding=\"async\" width=\"1274\" height=\"97\" src=\"https:\/\/www.veeble.com\/kb\/wp-content\/uploads\/2025\/02\/Screenshot-from-2025-02-04-12-15-46.png\" alt=\"using find command, we are deleting files older than 30 days in linux from the location \/var\/log\" class=\"wp-image-6871\" srcset=\"https:\/\/www.veeble.com\/kb\/wp-content\/uploads\/2025\/02\/Screenshot-from-2025-02-04-12-15-46.png 1274w, https:\/\/www.veeble.com\/kb\/wp-content\/uploads\/2025\/02\/Screenshot-from-2025-02-04-12-15-46-300x23.png 300w, https:\/\/www.veeble.com\/kb\/wp-content\/uploads\/2025\/02\/Screenshot-from-2025-02-04-12-15-46-1024x78.png 1024w, https:\/\/www.veeble.com\/kb\/wp-content\/uploads\/2025\/02\/Screenshot-from-2025-02-04-12-15-46-768x58.png 768w\" sizes=\"auto, (max-width: 1274px) 100vw, 1274px\" \/><\/a><\/figure>\n\n\n\n<p><\/p>\n\n\n<h2 class=\"wp-block-heading has-text-align-center\" id=\"automating-file-deletion\"><strong><span style=\"text-decoration: underline\">Automating File Deletion<\/span><\/strong><\/h2>\n\n\n<p>Automate the cleanup process using the find command within<strong> <a href=\"https:\/\/www.veeble.com\/kb\/cron-job-how-to-schedule-recurring-user-jobs\/\">cron jobs<\/a><\/strong> or a <strong><a href=\"https:\/\/www.veeble.com\/kb\/linux-bash-script-important-commands-to-know\/\">bash script<\/a><\/strong>, rather than executing commands manually. For temporary files, consider using the <strong><a href=\"https:\/\/linux.die.net\/man\/8\/tmpwatch\" target=\"_blank\" rel=\"noopener\">tmpwatch<\/a><\/strong> utility.<\/p>\n\n\n<h4 class=\"wp-block-heading has-text-align-center\" id=\"deletion-of-files-using-cron-job-and-find-command\">Deletion of Files using Cron Job and Find Command<\/h4>\n\n\n<p>To delete files older than 30 days automatically with the cron job, first execute the below command to open the cron job editor:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>crontab -e<\/code><\/pre>\n\n\n\n<p>Add the below line to delete old files from the location <em>\/var\/log<\/em> every day at <strong>3 AM<\/strong>:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">0 3 * * * find \/var\/log -type f -mtime +30 -exec rm -f {} \\;<\/pre>\n\n\n\n<p>You can modify the command to fit your needs. For example, instead of deleting files from \/var\/log, you might want to delete files from \/home\/cctv_recordings. If you&#8217;re still unsure about how to set up a cron job, you can find a detailed guide on how to do that here: <a href=\"https:\/\/www.veeble.com\/kb\/cron-job-how-to-schedule-recurring-user-jobs\/\" target=\"_blank\" rel=\"noreferrer noopener\">https:\/\/www.veeble.com\/kb\/cron-job-how-to-schedule-recurring-user-jobs\/<\/a><\/p>\n\n\n\n<figure class=\"wp-block-gallery has-nested-images columns-default is-cropped wp-block-gallery-1 is-layout-flex wp-block-gallery-is-layout-flex\">\n<figure class=\"wp-block-image size-full\"><a href=\"https:\/\/www.veeble.com\/kb\/wp-content\/uploads\/2025\/02\/crontab.gif\"><img loading=\"lazy\" decoding=\"async\" width=\"1920\" height=\"510\" data-id=\"6880\" src=\"https:\/\/www.veeble.com\/kb\/wp-content\/uploads\/2025\/02\/crontab.gif\" alt=\"Deletion of Files older than 90 days using Cron Job and Find Command in Linux\" class=\"wp-image-6880\"\/><\/a><\/figure>\n<\/figure>\n\n\n<h6 class=\"wp-block-heading\" id=\"examples\">Examples:<\/h6>\n\n\n<p>I will provide the exact entry to add to the file after running the command <strong>crontab -e<\/strong> for the following situations:<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li>Delete files older than <strong>7 days<\/strong> at <strong>2:15 AM<\/strong>:<\/li>\n<\/ol>\n\n\n\n<pre class=\"wp-block-preformatted\"><strong>15 2 <\/strong>* * * find \/var\/log -type f -mtime <strong>+7 <\/strong>-exec rm -f {} \\;<\/pre>\n\n\n\n<ol start=\"2\" class=\"wp-block-list\">\n<li>Delete files older than <strong>30 days<\/strong> at <strong>10:45 PM<\/strong>:<\/li>\n<\/ol>\n\n\n\n<pre class=\"wp-block-preformatted\"><strong>45 22<\/strong> * * * find \/var\/log -type f -mtime <strong>+30<\/strong> -exec rm -f {} \\;<\/pre>\n\n\n\n<p class=\"has-text-align-center\">(\ud83d\udc4610:45 PM in 24-hour format is represented as 45 22 in the crontab entry.)<\/p>\n\n\n\n<ol start=\"3\" class=\"wp-block-list\">\n<li>Delete files older than <strong>90 days<\/strong> at <strong>5:00 AM<\/strong>:<\/li>\n<\/ol>\n\n\n\n<pre class=\"wp-block-preformatted\"><strong>0 5 <\/strong>* * * find \/var\/log -type f -mtime <strong>+90<\/strong> -exec rm -f {} \\;<\/pre>\n\n\n\n<p><\/p>\n\n\n<h3 class=\"wp-block-heading has-text-align-center\" id=\"continuous-automatic-cleanup-of-old-files\">Continuous Automatic Cleanup of Old Files<\/h3>\n\n\n<p>If you prefer a continuous cleanup process instead of a scheduled one using a cron job, consider the following two approaches based on whether you&#8217;re dealing with temporary or regular files.<\/p>\n\n\n<h4 class=\"wp-block-heading\" id=\"automatic-cleanup-of-temporary-files-with-tmpwatch-command\">Automatic Cleanup of Temporary Files with tmpwatch Command<\/h4>\n\n\n<p><strong><a href=\"https:\/\/webhostinggeeks.com\/howto\/how-to-use-tmpwatch-to-auto-clean-up-files-and-logs-in-linux\/\" target=\"_blank\" rel=\"noopener\">tmpwatch<\/a><\/strong> is a specialized tool that we use for automatic, continuous cleanup for removing old temporary files. This may or may not be installed on your system. To install it, run the command below according to the package manager your OS uses:<\/p>\n\n\n\n<p>ie; for Ubuntu\/Debian:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo apt install tmpreaper<\/code><\/pre>\n\n\n\n<p class=\"has-text-align-left\">and for RedHat\/CentOS:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo yum install tmpwatch<\/code><\/pre>\n\n\n\n<p>After installing the tool, using it is simple. Simply type &#8220;tmpwatch&#8221; or &#8220;tmpreaper&#8221; then specify the number of hours in numerical format, followed by the target directory.<\/p>\n\n\n<h6 class=\"wp-block-heading\" id=\"examples\">Examples:<\/h6>\n\n\n<ol class=\"wp-block-list\">\n<li>Deleting files not accessed in the<strong> last 24 hours<\/strong> from <strong>\/tmp<\/strong> location:<\/li>\n<\/ol>\n\n\n\n<pre class=\"wp-block-code\"><code>tmpwatch 24 \/tmp<\/code><\/pre>\n\n\n\n<ol start=\"2\" class=\"wp-block-list\">\n<li>Deleting files not accessed in the <strong>last 48 hours<\/strong> from <strong>\/var\/log<\/strong> location:<\/li>\n<\/ol>\n\n\n\n<pre class=\"wp-block-code\"><code>tmpwatch 48 \/var\/log<\/code><\/pre>\n\n\n\n<p class=\"has-text-align-left\">(\ud83d\udc46If you have installed tmpreaper instead of tmpwatch, use tmpreaper in the command where you see the word &#8220;tmpwatch.&#8221; For example: tmpreaper 24 \/tmp.)<\/p>\n\n\n\n<p><\/p>\n\n\n<h4 class=\"wp-block-heading\" id=\"automatic-deletion-of-old-regular-files-using-bash-script-with-find\">Automatic Deletion of Old Regular Files using Bash Script with Find<\/h4>\n\n\n<p>For non-temporary files, using a <strong>bash script <\/strong>with the <strong>find <\/strong>command is a more effective method.<br>You can automate the file deletion commands from the previous section using a bash script. Follow these steps to create and run the script:<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li>Open a terminal and create a new script file using the following command:<\/li>\n<\/ol>\n\n\n\n<pre class=\"wp-block-code\"><code>vi cleanup.sh<\/code><\/pre>\n\n\n\n<p>This will open a text editor. <\/p>\n\n\n\n<ol start=\"2\" class=\"wp-block-list\">\n<li>Add the cleanup command with the find command in a bash script. Copy and paste the code below, replacing the directory path and adjusting the days from 7 to your desired number in the cleanup.sh file: <\/li>\n<\/ol>\n\n\n\n<pre class=\"wp-block-preformatted\">#!\/bin\/bash<br><strong>find <strong>\/path\/to\/directory<\/strong> f -mtime +7 -exec rm -f {} \\;<\/strong><br>echo \"Cleanup completed on $(date)\" &gt;&gt; \/var\/log\/cleanup.log<\/pre>\n\n\n\n<ol start=\"3\" class=\"wp-block-list\">\n<li>Then Save and exit by pressing <strong>CTRL+X<\/strong>, then <strong>Y<\/strong>, and hit <strong>Enter<\/strong>.<\/li>\n<\/ol>\n\n\n\n<div class=\"wp-block-group has-small-font-size is-nowrap is-layout-flex wp-container-core-group-is-layout-bcde1d39 wp-block-group-is-layout-flex\" style=\"padding-top:0;padding-right:0;padding-bottom:0;padding-left:0\">\n<p><strong>A line-by-line explanation of the code in the script:<\/strong><\/p>\n\n\n\n<figure class=\"wp-block-table is-style-stripes\"><table><thead><tr><th>Line<\/th><th>Explanation<\/th><\/tr><\/thead><tbody><tr><td>#!\/bin\/bash<\/td><td>Specifies that this is a Bash script.<\/td><\/tr><tr><td>find \/path\/to\/directory -type f -mtime +7 -exec rm -f {} \\;<\/td><td>Finds and deletes files older than 7 days.<\/td><\/tr><tr><td>echo &#8220;Cleanup completed on $(date)&#8221; &gt;&gt; \/var\/log\/cleanup.log<\/td><td>Logs the cleanup time for reference.<\/td><\/tr><\/tbody><\/table><\/figure>\n<\/div>\n\n\n\n<figure class=\"wp-block-gallery has-nested-images columns-default is-cropped wp-block-gallery-2 is-layout-flex wp-block-gallery-is-layout-flex\">\n<figure class=\"wp-block-image size-full\"><a href=\"https:\/\/www.veeble.com\/kb\/wp-content\/uploads\/2025\/02\/bashscript.gif\"><img loading=\"lazy\" decoding=\"async\" width=\"1920\" height=\"486\" data-id=\"6876\" src=\"https:\/\/www.veeble.com\/kb\/wp-content\/uploads\/2025\/02\/bashscript.gif\" alt=\"Automatic, Continuous Cleanup of Old Regular Files with Bash Script and using find command to delete files older than 7 days\" class=\"wp-image-6876\"\/><\/a><\/figure>\n<\/figure>\n\n\n\n<ol start=\"4\" class=\"wp-block-list\">\n<li>Make the script executable by executing the <a href=\"https:\/\/www.veeble.com\/kb\/what-do-chmod-755-644-and-others-mean\" target=\"_blank\" rel=\"noreferrer noopener\">chmod command <\/a>with executable permission for cleanup.sh file:<\/li>\n<\/ol>\n\n\n\n<pre class=\"wp-block-code\"><code>chmod +x cleanup.sh<\/code><\/pre>\n\n\n\n<ol start=\"5\" class=\"wp-block-list\">\n<li>Whenever you want to delete old files, run the script by executing the command manually with the command:<\/li>\n<\/ol>\n\n\n\n<pre class=\"wp-block-code\"><code>.\/cleanup.sh<\/code><\/pre>\n\n\n\n<figure class=\"wp-block-gallery has-nested-images columns-default is-cropped wp-block-gallery-3 is-layout-flex wp-block-gallery-is-layout-flex\">\n<figure class=\"wp-block-image size-full\"><a href=\"https:\/\/www.veeble.com\/kb\/wp-content\/uploads\/2025\/02\/Screenshot-from-2025-02-04-13-49-17.png\"><img loading=\"lazy\" decoding=\"async\" width=\"1901\" height=\"530\" data-id=\"6874\" src=\"https:\/\/www.veeble.com\/kb\/wp-content\/uploads\/2025\/02\/Screenshot-from-2025-02-04-13-49-17.png\" alt=\"Automatic, Continuous Cleanup of Old Regular Files using bash script and find command\" class=\"wp-image-6874\" srcset=\"https:\/\/www.veeble.com\/kb\/wp-content\/uploads\/2025\/02\/Screenshot-from-2025-02-04-13-49-17.png 1901w, https:\/\/www.veeble.com\/kb\/wp-content\/uploads\/2025\/02\/Screenshot-from-2025-02-04-13-49-17-300x84.png 300w, https:\/\/www.veeble.com\/kb\/wp-content\/uploads\/2025\/02\/Screenshot-from-2025-02-04-13-49-17-1024x285.png 1024w, https:\/\/www.veeble.com\/kb\/wp-content\/uploads\/2025\/02\/Screenshot-from-2025-02-04-13-49-17-768x214.png 768w, https:\/\/www.veeble.com\/kb\/wp-content\/uploads\/2025\/02\/Screenshot-from-2025-02-04-13-49-17-1536x428.png 1536w\" sizes=\"auto, (max-width: 1901px) 100vw, 1901px\" \/><\/a><\/figure>\n<\/figure>\n\n\n\n<ol start=\"6\" class=\"wp-block-list\">\n<li>If you want this script to run automatically (for example: every day at midnight), add it to a cron job by opening the crontab with the command:<\/li>\n<\/ol>\n\n\n\n<pre class=\"wp-block-code\"><code>crontab -e<\/code><\/pre>\n\n\n\n<p>Then add the following line to it:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>0 0 * * * \/path\/to\/cleanup.sh<\/code><\/pre>\n\n\n\n<p>This will execute the script daily at midnight.<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><a href=\"https:\/\/www.veeble.com\/kb\/wp-content\/uploads\/2025\/02\/crontab-bashscript.gif\"><img loading=\"lazy\" decoding=\"async\" width=\"1920\" height=\"492\" src=\"https:\/\/www.veeble.com\/kb\/wp-content\/uploads\/2025\/02\/crontab-bashscript.gif\" alt=\"Automatically deleting files older than 30 days in Linux using bashscript and cron tab with the find command.\" class=\"wp-image-6878\"\/><\/a><\/figure>\n\n\n\n<div class=\"wp-block-uagb-separator uagb-block-610a31e2\"><div class=\"wp-block-uagb-separator__inner\" style=\"--my-background-image:\"><\/div><\/div>\n\n\n\n<p>You can delete files that are older than a specified number of days by following this tutorial. This blog explains different methods for deleting files, whether they are older than 7, 30, or 90 days. It covers manual and automated deletion techniques to help you manage storage and improve system performance in Linux.<\/p>\n\n\n<h6 class=\"wp-block-heading has-text-align-center\" id=\"frequently-asked-old-file-deletion-methods\"><span style=\"text-decoration: underline\">Frequently Asked Old File Deletion Methods<\/span><\/h6>\n\n\n<p><strong>1.<\/strong> <strong>How can I delete a specific file type that is older than X days?<\/strong><br>If you want to delete only specific file types, such as logs or backups, you can specify the file type using the <strong>-type<\/strong> and <strong>-name<\/strong> flags in the find option. The -type option in the find command specifies the command to target files or directories, while the -name option specifies which file names to delete.<br>For example:<br>To delete all <em>.txt<\/em> files older than 30 days in the <em>\/home\/user\/documents<\/em> directory, you would use the following command:<br><code>find \/home\/user\/documents -type f -name \"*.txt\" -mtime +30 -delete<\/code><\/p>\n\n\n\n<p><strong>2. How can I delete empty directories<\/strong> <strong>in Linux?<\/strong><br>Sometimes, after deleting files, you&#8217;re left with a bunch of empty directories. You can use the&nbsp;find&nbsp;command to remove these empty directories with the help of the <strong>-empty<\/strong> flag. To do this, use&nbsp;<strong>-type d<\/strong>&nbsp;to target directories and&nbsp;<strong>-empty&nbsp;<\/strong>to locate only those that are empty<strong>.<\/strong><br>For example:<br>To delete all empty directories within <em>\/home\/user\/projects<\/em>:<br><code>find \/home\/user\/projects -type d -empty -delete<\/code><\/p>\n\n\n\n<div style=\"height:25px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<div class=\"wp-block-uagb-call-to-action uagb-block-714a7c5b wp-block-button\"><div class=\"uagb-cta__wrap\"><h3 class=\"uagb-cta__title\">Unlimited Bandwidth Windows Hosting<\/h3><p class=\"uagb-cta__desc\">Host without traffic worries! Our unlimited bandwidth Windows plans feature optimized IIS for top performance.<\/p><\/div><div class=\"uagb-cta__buttons\"><a href=\"https:\/\/www.veeble.com\/in\/windows-hosting\/\" class=\"uagb-cta__button-link-wrapper wp-block-button__link\" target=\"_blank\" rel=\"noopener noreferrer\">Start Hosting<svg xmlns=\"https:\/\/www.w3.org\/2000\/svg\" viewBox=\"0 0 512 512\"><path d=\"M504.3 273.6l-112.1 104c-6.992 6.484-17.18 8.218-25.94 4.406c-8.758-3.812-14.42-12.45-14.42-21.1L351.9 288H32C14.33 288 .0002 273.7 .0002 255.1S14.33 224 32 224h319.9l0-72c0-9.547 5.66-18.19 14.42-22c8.754-3.809 18.95-2.075 25.94 4.41l112.1 104C514.6 247.9 514.6 264.1 504.3 273.6z\"><\/path><\/svg><\/a><\/div><\/div>\n","protected":false},"excerpt":{"rendered":"<p>Learn how to delete files older than any number of days in Linux using this easy to understand tutorial with screenshots.<\/p>\n","protected":false},"author":7,"featured_media":8374,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_uag_custom_page_level_css":"","site-sidebar-layout":"default","site-content-layout":"","ast-site-content-layout":"default","site-content-style":"default","site-sidebar-style":"default","ast-global-header-display":"","ast-banner-title-visibility":"","ast-main-header-display":"","ast-hfb-above-header-display":"","ast-hfb-below-header-display":"","ast-hfb-mobile-header-display":"","site-post-title":"","ast-breadcrumbs-content":"","ast-featured-img":"","footer-sml-layout":"","theme-transparent-header-meta":"","adv-header-id-meta":"","stick-header-meta":"","header-above-stick-meta":"","header-main-stick-meta":"","header-below-stick-meta":"","astra-migrate-meta-layouts":"set","ast-page-background-enabled":"default","ast-page-background-meta":{"desktop":{"background-color":"var(--ast-global-color-4)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"ast-content-background-meta":{"desktop":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"footnotes":"[]"},"categories":[5],"tags":[],"class_list":["post-6849","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-linux"],"uagb_featured_image_src":{"full":["https:\/\/www.veeble.com\/kb\/wp-content\/uploads\/2025\/02\/How-to-Delete-Files-Older-Than-30-Days-in-Linux-Easily.jpg",1366,768,false],"thumbnail":["https:\/\/www.veeble.com\/kb\/wp-content\/uploads\/2025\/02\/How-to-Delete-Files-Older-Than-30-Days-in-Linux-Easily-150x150.jpg",150,150,true],"medium":["https:\/\/www.veeble.com\/kb\/wp-content\/uploads\/2025\/02\/How-to-Delete-Files-Older-Than-30-Days-in-Linux-Easily-300x169.jpg",300,169,true],"medium_large":["https:\/\/www.veeble.com\/kb\/wp-content\/uploads\/2025\/02\/How-to-Delete-Files-Older-Than-30-Days-in-Linux-Easily-768x432.jpg",768,432,true],"large":["https:\/\/www.veeble.com\/kb\/wp-content\/uploads\/2025\/02\/How-to-Delete-Files-Older-Than-30-Days-in-Linux-Easily-1024x576.jpg",1024,576,true],"1536x1536":["https:\/\/www.veeble.com\/kb\/wp-content\/uploads\/2025\/02\/How-to-Delete-Files-Older-Than-30-Days-in-Linux-Easily.jpg",1366,768,false],"2048x2048":["https:\/\/www.veeble.com\/kb\/wp-content\/uploads\/2025\/02\/How-to-Delete-Files-Older-Than-30-Days-in-Linux-Easily.jpg",1366,768,false]},"uagb_author_info":{"display_name":"Adrian Antony","author_link":"https:\/\/www.veeble.com\/kb\/author\/adrian\/"},"uagb_comment_info":0,"uagb_excerpt":"Learn how to delete files older than any number of days in Linux using this easy to understand tutorial with screenshots.","_links":{"self":[{"href":"https:\/\/www.veeble.com\/kb\/wp-json\/wp\/v2\/posts\/6849","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.veeble.com\/kb\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.veeble.com\/kb\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.veeble.com\/kb\/wp-json\/wp\/v2\/users\/7"}],"replies":[{"embeddable":true,"href":"https:\/\/www.veeble.com\/kb\/wp-json\/wp\/v2\/comments?post=6849"}],"version-history":[{"count":23,"href":"https:\/\/www.veeble.com\/kb\/wp-json\/wp\/v2\/posts\/6849\/revisions"}],"predecessor-version":[{"id":8804,"href":"https:\/\/www.veeble.com\/kb\/wp-json\/wp\/v2\/posts\/6849\/revisions\/8804"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.veeble.com\/kb\/wp-json\/wp\/v2\/media\/8374"}],"wp:attachment":[{"href":"https:\/\/www.veeble.com\/kb\/wp-json\/wp\/v2\/media?parent=6849"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.veeble.com\/kb\/wp-json\/wp\/v2\/categories?post=6849"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.veeble.com\/kb\/wp-json\/wp\/v2\/tags?post=6849"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}