Linux Bash Shell - File globbing specific range?

10

I have a bunch of files in a folder:

spreadsheet700.xls spreadsheet800.xls spreadsheet850.xls spreadsheet1005.xls spreadsheet2400.xls

how can I use file globbing to select files that numbers end in 700 or higher, but less than 1000 and put them into a new folder?

I've tried:

cp spreadsheet*.xls but the wildcard selects all. Thanks in adance.

BubbleMonster

Posted 2014-02-13T12:36:14.930

Reputation: 382

Please [edit] your question to include (and tag) the program language or shell you are using so we don't have to guess. This makes it useful for others who search similar questions. – CharlieRB – 2014-02-13T12:45:23.143

Done - Apologies for not including that info – BubbleMonster – 2014-02-13T21:10:58.273

Answers

4

cp spreadsheet{7,8,9}[0-9][0-9].xls folder

This means starting with 7 or 8 or 9 and with two more digits so therefore 7xx,8xx,9xx

fede.evol

Posted 2014-02-13T12:36:14.930

Reputation: 1 718

just a note if using quotes, the special chars need to be outside just like the * wildcard – myol – 2019-12-10T15:42:55.190

Works perfectly, didn't know I could use {} with [] thanks – BubbleMonster – 2014-02-13T12:45:01.940

Also spreadsheet[789][0-9][0-9].xls works the same but I thought the curly brackets make it more evident – fede.evol – 2014-02-13T12:47:18.810

10

You could also do this:

cp spreadsheet{700..999}.xls folder

This is simpler and also gives you more precision on starting and ending the range (the accepted answer only works if you want to get the same sets of digits for 7xx, 8xx and 9xx).

otocan

Posted 2014-02-13T12:36:14.930

Reputation: 101