14

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.

Oliver Salzburg
  • 86,445
  • 63
  • 260
  • 306
BubbleMonster
  • 430
  • 6
  • 17
  • 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 Feb 13 '14 at 12:45
  • Done - Apologies for not including that info – BubbleMonster Feb 13 '14 at 21:10

2 Answers2

18

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).

It's called Brace Expansion:
https://www.gnu.org/software/bash/manual/html_node/Brace-Expansion.html

otocan
  • 281
  • 2
  • 5
  • 1
    Is this documented somewhere? – rustyx Nov 20 '20 at 09:37
  • 1
    In the bash manpage search for "Brace Expression". -- A sequence expression takes the form {x..y[..incr]}, where x and y are either integers or single characters, and incr, an optional increment, is an integer. – Jeremy Jan 04 '21 at 21:32
  • Thanks both, it appears to be called "Brace Expansion" and the answer has been updated to link to the documentation. – otocan Aug 23 '21 at 13:26
8

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
  • 1,918
  • 1
  • 12
  • 6