Finding And Deleting Old Files (on Unix and Windows)

I needed to write short scripts to delete old files on a Windows Server. It’s a very easy task on UNIX flavors but the limited capacity of Windows command line made me worried. You can use a simple “find” command to find old files on UNIX. For example, the following command will be enough to find and delete files older than 7 days:

For the ones who are not familiar with the find command, I’ll try to explain its parameters. The parameter “-type f” is not mandatory but it will help you find only “files” (and filter out directories etc). The parameter “exec” lets you run a command for the selected files. The brackets are replaced with the name of the selected file. The plus sign (+) will make the command line is built by appending each selected file name at the end.

While searching the net, I found that Windows has a useful command to handle mass files. Here’s the Windows version of the above command:

You need to enter negative values to find old files on windows. The parameter “/s” is to search into subdirectories recursively, and the parameter “/c” is to run a command. @path is the full path name of the selected file. It’s better than I expected 🙂

Please share
  • 2
  •  
  •  
  •  
  •  
  •  

AWS Big Data Specialist. Oracle Certified Professional (OCP) for EBS R12, Oracle 10g and 11g. Co-author of "Expert Oracle Enterprise Manager 12c" book published by Apress. Awarded as Oracle ACE (in 2011) and Oracle ACE Director (in 2016) for the continuous contributions to the Oracle users community. Founding member, and vice president of Turkish Oracle User Group (TROUG). Presented at various international conferences including Oracle Open World.

Leave Comment

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.