Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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 
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
up vote 8 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

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .