Copying numerical range of folders

Jason Crain jason at
Thu Jan 22 22:55:37 UTC 2009

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.

More information about the ubuntu-users mailing list