Skip to content
Advertisement

Copy numbered image files where number is less than X

I have a folder of 10,000 JPEg’s labeled 1.JPG to 10000.JPG. I want to copy all files that have a number less than (or greater than) X to another directory. What’s the best way to do this from the command line?

Advertisement

Answer

A simple brace expression would zap this, here I am guessing at your number range of course:

cp {25..400}.jpg another_dir

More information on brace expressions here: http://www.linuxjournal.com/content/bash-brace-expansion which includes:

The syntax for brace expansion consists of either a sequence specification or a comma separated list of items inside curly braces “{}”. A sequence consists of a starting and ending item separated by two periods “..”.

User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement