unixubuntumv

Move sets of files with date encoded names


I have a set of files that have dates in them.

lets call them:

 a20120528_120001.log
 b20120528_120003.log
 (name)(year)(month)(day)_(hour)(minute)(second).log

It is easy enough to move these two files simultaneously by doing:

 mv *20120528_12* file/

But now I have a situation where I want to move several hours worth of files in the same day ie:

 a20120528_120001.log
 b20120528_120003.log
 a20120528_130001.log
 b20120528_130003.log
 a20120528_140001.log
 b20120528_140003.log

Now if i wanted to transfer all of them i could just do the day:

 mv *20120528* file/

but what can I do if I only want to move hours 12 and 13, but exclude 14.

Please note this will need to be generic enough that i can input the date, because this will extend to be used across multiple days where there are 24 logs per day and several (between 3-8) will be excluded from each day.

How would I do this?


Solution

  • You can use ranges:

    mv *20120528_1[23]* file/
    

    For excluding everything from 3-8, go with the slightly more complicated:

    mv *20120528_{0[0-29],[12]*}*