Copying numerical range of folders

Florian Diesch diesch at spamfence.net
Fri Jan 23 01:48:19 UTC 2009


Jason Crain <jason at bluetree.ath.cx> 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

If you want to copy very much folders this doesn't work as the
command line gets to long.

This should work:

 seq -f '"cp -r /folder/k%g  /dest"' 8100 8945 | xargs -l1 -- sh -c




   Florian
-- 
<http://www.florian-diesch.de/>
-----------------------------------------------------------------------
**  Hi! I'm a signature virus! Copy me into your signature, please!  **
-----------------------------------------------------------------------




More information about the ubuntu-users mailing list