If I have two files (in a folder with similarly numbered files) such as


And I want to use a glob on them, do I do it like so:

cp -r /folder1/*.{19,20} /folder2/

or like so?

cp -r /folder1/{*.19,*.20} /folder2/

Neither seem to expand out when I tap tab.

Is one 'better than the other? What order does it expand in? Will it ever matter?

  • 1
    Are those numbers as intended? – a CVn Jul 19 '13 at 8:21
  • For numeric brace expansions, you can also use {0..N}. – Chris Down Jul 19 '13 at 8:39
  • @ChrisDown does it work with double digits? I'm sure I've only seen it work with single digits at work. – Pureferret Jul 19 '13 at 9:08
  • @Pureferret At least on 4.2.45, yes. sprunge.us/VfOX – Chris Down Jul 19 '13 at 9:59
  • I think we must have a much older version than that. – Pureferret Jul 19 '13 at 10:06

No, it doesn't matter. bash expands the glob after expanding the braces, so either will work.

$ tee foo bar baz </dev/null
$ echo *{a,o}*
bar baz foo
$ echo {*a*,*o*} 
bar baz foo
$ echo {*,*}
bar baz foo bar baz foo
  • And if you do want to do globbing here instead of expanding several globs after brace expansion, you can use ksh extended globbing with echo *.@(19|29) (enabled in bash with shopt -s extglob). – Stéphane Chazelas Jul 19 '13 at 10:11

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.