Hello,
Currently I have a painstaking process that I use to move file for a monthly archive. I have to run the same two commands for 24 different directories. I wish to have a script with a for loop automate this and I have not been able to succeed. Here is what I do 24 times. I know this is possible with a range of some how.
$ FILES=`find /mnt/raw_vendor_data/raw_1_hist/primary/ -type f | xargs ls -l | grep May | awk '{print $NF}'`
$ mv $FILES /mnt/raw_vendor_data/raw_data_archive/RAW_1_MAY_2011/
My Failed Attempt.
#!/bin/bash
for i in {1..24} ; do
FILES=`find /mnt/raw_vendor_data/raw_${i}_hist/primary/ -type f | xargs ls -l | grep May | awk '{print $NF}'`
mv $FILES /mnt/raw_vendor_data/raw_data_archive/RAW_${i}_MAY_2011
done
Hello,
Maybe I am not understanding your code correctly.
The files that I wish to move live in separate directories and the target directories are separate as well. That find command you have posted seems to just search . current working directory, it does not iterate through all of them from what I can tell. Also it looks like it is moving the files ../ back one directory.
Each time I run the command that I am using I need to increment the integer.
Command Set 1:
$FILES=`find /mnt/raw_vendor_data/raw_1_hist/primary/ -type f | xargs ls -l | grep May | awk '{print $NF}'`
$mv $FILES /mnt/raw_vendor_data/raw_data_archive/RAW_1_MAY_2011/
Command Set 2:
$FILES=`find /mnt/raw_vendor_data/raw_2_hist/primary/ -type f | xargs ls -l | grep May | awk '{print $NF}'`
$mv $FILES /mnt/raw_vendor_data/raw_data_archive/RAW_2_MAY_2011
So basically I run the 2 command sets 24 times. I will do automate this process.
I posted a sample script to show how to increment the variable and use it in find. You might need to adopt the same technique and do the changes accordingly.