Can I use shell wildcards to select filenames ranging across double-digit numbers (e.g., from foo_1.jpg to foo_54.jpg)?

DQdlM picture DQdlM · Jun 22, 2011 · Viewed 17.1k times · Source

I have a directory with image files foo_0.jpg to foo_99.jpg. I would like to copy files foo_0.jpg through foo_54.jpg.

Is this possible just using bash wildcards?

I am thinking something like cp foo_[0-54].jpg but I know this selects 0-5 and 4 (right?)

Also, if it is not possible (or efficient) with just wildcards what would be a better way to do this?

Thank you.

Answer

glenn jackman picture glenn jackman · Jun 22, 2011

I assume you want to copy these files to another directory:

cp -t target_directory foo_{0..54}.jpg