Article 57ZFG Script to move files by filename patterns

Script to move files by filename patterns

by
solidbulk
from LinuxQuestions.org on (#57ZFG)
Hi,

I am trying to use a script I can add to the root crontab to move files by their filename patterns.
I have two directories, their names are Prepared and Fixed.
/home/oracle/Desktop/Prepared
/home/oracle/Desktop/Fixed
I need a script to check all the filenames in each folder, if a 12 character timestamp string portion of the filename in the Prepared directory matches to another file in the Fixed directory and contains the string 'complete' in the filename , move that file from the Prepared directory to the Fixed directory. So in the following scenario I would like mdata_090620202050.txt and mdata_083020201927.txt to be moved by the script from the Prepared to the Fixed directory.

Before:
/home/oracle/Desktop/Prepared
-rw-r--r--. 1 oracle oracle 1304 Sep 6 20:50 mdata_090620202050.txt
-rw-r--r--. 1 oracle oracle 1304 Sep 5 20:50 mdata_090520201535.txt
-rw-r--r--. 1 oracle oracle 1304 Aug 30 20:50 mdata_083020201927.txt
/home/oracle/Desktop/Fixed
-rw-rw-r--. 1 oracle oracle 34261 Sep 7 10:10 mdata_090620202050_1000000000003_complete.txt
drwxrwxrwx. 2 oracle oracle 8531312 Sep 7 19:50 .
-rw-rw-r--. 1 oracle oracle 44027 Sep 5 10:10 mdata_090520201535_1000000000002_processing.txt
-rw-rw-r--. 1 oracle oracle 44817 Aug 30 10:10 mdata_083020201927_1000000000001_complete.txt

After:
/home/oracle/Desktop/Prepared
-rw-r--r--. 1 oracle oracle 1304 Sep 5 20:50 mdata_090520201535.txt
/home/oracle/Desktop/Fixed
-rw-rw-r--. 1 oracle oracle 34261 Sep 7 10:10 mdata_090620202050_1000000000003_complete.txt
drwxrwxrwx. 2 oracle oracle 8531312 Sep 7 19:50 .
-rw-rw-r--. 1 oracle oracle 44027 Sep 5 10:10 mdata_090520201535_1000000000002_processing.txt
-rw-rw-r--. 1 oracle oracle 44817 Aug 30 10:10 mdata_083020201927_1000000000001_complete.txt
-rw-r--r--. 1 oracle oracle 1304 Aug 30 20:50 mdata_083020201927.txt
-rw-r--r--. 1 oracle oracle 1304 Sep 6 20:50 mdata_090620202050.txt

Red Hat Enterprise Linux Server release 7.6

Thanks!latest?d=yIl2AUoC8zA latest?i=f8IX85BVd_A:KLjbh5KNUwQ:F7zBnMy latest?i=f8IX85BVd_A:KLjbh5KNUwQ:V_sGLiP latest?d=qj6IDK7rITs latest?i=f8IX85BVd_A:KLjbh5KNUwQ:gIN9vFwf8IX85BVd_A
External Content
Source RSS or Atom Feed
Feed Location https://feeds.feedburner.com/linuxquestions/latest
Feed Title LinuxQuestions.org
Feed Link https://www.linuxquestions.org/questions/
Reply 0 comments