Copying numerical range of folders

Lorenzo Luengo lluengo at dgeo.udec.cl
Thu Jan 22 23:06:52 UTC 2009


Jason Crain wrote:
> Oliver Marshall wrote:
>   
>> Whats the best way of copying a range of folders which have the name in 
>> the form of Knnnnn from one folder to another? I want to copy K8100 to 
>> K8945. I’ve tried;
>>
>> Sudo cp /folder/k8[100-945] /folder2 blah blah
>>
>> But that tells me there are no folders called k8[100-945]. However the 
>> following does work;
>>
>> Sudo cp /folder/k810[0-9] /folder2 blah blah
>>
>> But that only copies 10 folders at a time, and I would have to do the 
>> copy in lots of chunks through the night.
>>     
>
> The seq command sounds like what you want.  This command:
> seq -f '/folder/k%g' -s' ' 8100 8945
>
> will print a list of folders like this: /folder/k8100 /folder/k8101 
> /folder/k8102 /folder/k8103
>
> So you can combine it with the cp command:
> cp -r `seq -f '/folder/k%g' -s' ' 8100 8945` /dest
>
>
> The [] does character matching, not sequences.  For example a[abc] will 
> match aa, ab, and ac.
>
>   
yep ... seq is the tool you need

may be you can do

a=`seq 8100 8945`
for k in $a;
do
cp /folder/k$k /dest/;
done;

I hope it works for you.

-- 
Lorenzo Luengo Contreras
Administrador de Sistemas DGEO
Universidad de Concepción
Concepción - Chile
+56-41-2207277





More information about the ubuntu-users mailing list