-1

I want to create files like song1.mp3,song2.mp3,song3.mp3... in my home directory.How to create this using for loop?

4

No for loop needed if they're consecutive numbers:

touch ~/song{1..20}.mp3
1

DopeGhoti's answer is more succint, but if you're dead-set on a for loop,

for i in $(seq 1 5); do
    touch song${i}.mp3;
done;

Should do the trick.

$(seq 1 5) evaluates to 1 2 3 4 5, and then the for-loop iterates over that sequence. Replace 1 and 5 with whatever values you need.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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