How to delete all files older than 3 days when "Argument list too long"?

delete files older than 30 days in unix
delete files older than 7 days in unix
delete files older than 7 days windows
shell script to delete files older than 7 days
linux delete files older than specific date
batch script to delete files older than 30 days
shell script to delete files older than one month
linux delete files older than 1 hour

I've got a log file directory that has 82000 files and directories in it (about half and half).

I need to delete all the file and directories which are older than 3 days.

In a directory that has 37000 files in it, I was able to do this with:

find * -mtime +3 -exec rm {} \;

But with 82000 files/directories, I get the error:

/usr/bin/find: Argument list too long

How can I get around this error so that I can delete all files/directories that are older than 3 days?

To delete all files and directories within the current directory:

find . -mtime +3 | xargs rm -Rf

Or alternatively, more in line with the OP's original command:

find . -mtime +3 -exec rm -Rf -- {} \;

How to Delete Files Older than X Days on Windows, The –lt (less than) operator is then used to compare the CreationTime property of the objects with Get-Date (the current date) subtract 5 days. Delete Files Older Than X Days with File Explorer. Open the Search tools tab in the Ribbon (F3). Click on the Date modified button. It has a drop down list with options. Select the desired option, like Last week. File Explorer will filter the results immediately. Select the files you don't need, and press the Delete key to delete files.

Can also use:

find . -mindepth 1 -mtime +3 -delete

To not delete target directory

How to delete files older than 30 days in Linux, This is the best practice to remove old unused files from your server. For example​, if we are running daily/hourly backup of files or database on the server then  How to Delete Files Older than X Days on Windows Taylor Gibb @taybgibb December 24, 2012, 2:00am EDT We have already shown you how flexible the Linux shell can be , but that’s not to say Windows is any further behind.

Another solution for the original question, esp. useful if you want to remove only SOME of the older files in a folder, would be smth like this:

find . -name "*.sess" -mtime +100 

and so on.. Quotes block shell wildcards, thus allowing you to "find" millions of files :)

How To Delete Files Older Than X Days in Windows 10, How do you delete files from older than 30 days? I need to delete all the file and directories which are older than 3 days. In a directory that has 37000 files in it, I was able to do this with: find * -mtime +3 -exec rm {} \; But with 82000 files/directories, I get the error: /usr/bin/find: Argument list too long

How to Delete Files Older than N Days Automatically in Windows , How do I delete files older than 7 days UNIX? Perhaps, the easiest way to delete files at a certain age is through a command line or a batched file or even a script. Yes, of course, you can still do so from the powerful File Explorer that comes with Windows but it certainly takes more steps than a simple command.

Delete files older than X days +, To delete files older that X days, do the following. Open a new command prompt instance. Type the following command: ForFiles /p "C:\My Folder" /s /d -30 /c "cmd /c del @file" Substitute the folder path and the amount of days with desired values and you are done. These commands will not ask you any confirmation before deleting the files. It will simply delete the files once you hit the ENTER key. So be very careful and double check the files you’re about to delete. Find and Delete Files Older Than X Days In Linux. First, let us find out the files older than X days, for example 30 days. To do, so, just run:

Linux: Delete Files Older Than X Days, 3 Shares. Windows 10 has built-in features to free up space by deleting old files in the To delete files that are older than a certain number of days in a “custom”​  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’ll 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.

Comments
  • Have you tried find -mtime +3 -exec rm {} + ?
  • I believe running find * -mtime +3 |xargs rm would solve that problem.
  • I think the only problem is find *. find . is better. The shell globing with expand the * to a huge list of files and directories.
  • @artlessnoise is spot on.
  • -1 The problem is the star in "find *", you solved it by using "find ." instead. Xargs is misleading here.
  • @AleksandrLevchuk it solves OPs problem, and therefore does not deserve a downvote
  • Question: "find * -mtime +3 -exec rm {} \;" gives Argument list too long. Answer: Use "find . -mtime +3 -exec rm {} \;"
  • You might want to add -- after rm, like find . -mtime +3 -exec rm -- {} \;
  • Nobody said what the -- is for.
  • Best answer, much cleaner than calling rm (and probably safer). Works for subdirectories as well.