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 this post Share on Facebook2Share on Google+0Share on LinkedIn4Share on Reddit0Tweet about this on Twitter

Gokhan Atil is a database architect who has hands-on experience with both RDBMS and noSQL databases (Oracle, PostgreSQL, Microsoft SQL Server, Sybase IQ, MySQL, Cassandra, MongoDB and ElasticSearch), and strong background on software development. He is certified as Oracle Certified Professional (OCP) and is awarded as Oracle ACE (in 2011) and Oracle ACE Director (in 2016) for his continuous contributions to the Oracle users community.

Leave Comment

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