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.

  • 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 Feb 13 '14 at 21:10

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

  • Works perfectly, didn't know I could use {} with [] thanks Feb 13 '14 at 12:45
  • Also spreadsheet[789][0-9][0-9].xls works the same but I thought the curly brackets make it more evident
    – fede.evol
    Feb 13 '14 at 12:47
  • just a note if using quotes, the special chars need to be outside just like the * wildcard
    – myol
    Dec 10 '19 at 15:42

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:

  • 1
    Is this documented somewhere?
    – rustyx
    Nov 20 '20 at 9: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 4 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 at 13:26

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.