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 http://www.biterscripting.com
script movefiles.txt date(today's date)
- Save the script as C:Scriptsmovefiles.txt.
- Start biterscripting.
- Call the script as:
The above will move files that have not been modified since 30 days before today.
Thanks to SenHu
for this tip on the forum.