Batch script to delete file older than 30 days

October 2016

Shell Scripting is a powerful way to handle files on Linux. One can write custom Shell scripts that can be used to copy or delete old files. After writing out the code, one needs to save it as a file and run it in batch mode. Once the code has run on batch mode, the user should be able to move or delete old files as per their needs.


I would like to create a batch script which could copy files which are older than 30 days from one folder to another. I want it to also delete the 30 days old files from the source folder after copying to the destination folder.


The following windows script will move files older than a given date from C:folder1 to C:folder2. By older, I am assuming that they are not modified after a certain date.

The date is passed in the format yyyymmdd. When files are moved to folder2, they are automatically deleted from folder1.

# Script movefiles.txt    
# Input argument - date    
var str date    

# Get a list of files not modified since $date.    
var str list ; lf -n "*" "C:folder1" ( ($ftype == "f") AND ($fmtime < $date) ) > $list    
# Move files one by one.    
while ($list <> "")    
    var str file ; lex "1" $list > $file    
    system move $file "C:folder2"    

The script is in biterscripting. Download biterscripting from .
  • Save the script as C:Scriptsmovefiles.txt.
  • Start biterscripting.
  • Call the script as:

script movefiles.txt date(today's date)

The above will move files that have not been modified since 30 days before today.


Thanks to SenHu for this tip on the forum.

Related :

This document entitled « Batch script to delete file older than 30 days » from CCM ( is made available under the Creative Commons license. You can copy, modify copies of this page, under the conditions stipulated by the license, as this note appears clearly.