Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Slightly stumped on what CP command would copy files numbered 14 trough 39 into a directory called Volume2 from the following example:

01.mp3  04.mp3  07.mp3  10.mp3  13.mp3  16.mp3  19.mp3  22.mp3  25.mp3  28.mp3  31.mp3  34.mp3  37.mp3
02.mp3  05.mp3  08.mp3  11.mp3  14.mp3  17.mp3  20.mp3  23.mp3  26.mp3  29.mp3  32.mp3  35.mp3  38.mp3
03.mp3  06.mp3  09.mp3  12.mp3  15.mp3  18.mp3  21.mp3  24.mp3  27.mp3  30.mp3  33.mp3  36.mp3  39.mp3 
Volume2
share|improve this question
    
No cp command would do that. –  Ignacio Vazquez-Abrams Jul 17 '12 at 2:48
    
cp {14..39}.mp3 Volume2 does it on my system...assuming the directory exists, of course. –  user55325 Jul 17 '12 at 2:50

1 Answer 1

up vote 4 down vote accepted

You could just do

cp {14..39}.mp3 Volume2

But the for-loop is handy for other things:

for f in {14..39}.mp3; do cp "$f" Volume2; done
share|improve this answer
    
Thanks. Both answers are very helpful. –  user98496 Jul 17 '12 at 2:49
    
thanks for the edit. :P –  user55325 Jul 17 '12 at 2:52
    
Not homework, though I am an on again/off again student focusing on Linux Admin. –  user98496 Jul 17 '12 at 2:53
    
Awesome. Will give cp {14..39}.mp3 Volume2 a try. –  user98496 Jul 17 '12 at 2:56
    
Just for completion: the for-loop will have N cp invocations where N is the number of songs, as compared to the single invocation of the first example. Fewer invocations means faster and less resource intensive (in this simple case it doesn't matter in practice, though). A caveat is that if the expanded list exceeds ARG_MAX-1 (check value with getconf ARG_MAX, it is much higher than 39-14) number of entries, it will fail. Utilities such as xargs and find can take care of this caveat by splitting on ARG_MAX. –  Daniel Andersson Jul 17 '12 at 8:37

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.