6

I need to create 26 files named a to z in single command. I thought touch command would be sufficient with the regex, but it doesn't expand [a-z] instead it creates a single file with name "[a-z]".

$ touch [a-z]

Any way to achieve these?

Note:

$ bash -version
 GNU bash, version 4.3.30(1)-release (i686-pc-linux-gnu)
Gilles 'SO- stop being evil'
  • 807,993
  • 194
  • 1,674
  • 2,175
mtk
  • 26,802
  • 35
  • 91
  • 130

1 Answers1

13

In bash (version 3.0 (2004) and above), ksh (since ksh93r (2006)) and zsh (version 5.0.6 (2014) and above):

touch {a..z}

(note that only zsh supports characters other than ASCII letters and digits, none goes as far as perl's .. operator which inspired those shells operators).

With other zsh version (since 2.2 (1992)):

setopt braceccl
touch {a-z}
Stéphane Chazelas
  • 522,931
  • 91
  • 1,010
  • 1,501
cuonglm
  • 150,973
  • 38
  • 327
  • 406
  • Just tested it and that works great on Ubuntu. – Rick Chatham Aug 20 '15 at 17:13
  • bash and zsh and some other shells will expand {a..z} to an ASCII sequence of 26 separate arguments. Your /bin/sh however might not know about it. – VaTo Aug 20 '15 at 17:16
  • Thanks for your response. still no success, I am bash 4.3 – mtk Aug 20 '15 at 17:20
  • cool. it works like a charm. I was giving wrong command. it is `..` and not hyphen.. Thanks – mtk Aug 20 '15 at 17:20
  • @SaulOrtega: Yes, of course, that's why I mention only `bash`, `ksh` and `zsh`. – cuonglm Aug 20 '15 at 17:21
  • I do wonder about the logic that led bash, at least, to restrict it to letters, but allow ranges to span between upper and lower case including `[]^_\``. – Random832 Aug 20 '15 at 21:27
  • @Stéphane Chazelas: Is this edit conflicted with your one [here](http://unix.stackexchange.com/a/92829/38906) – cuonglm Aug 21 '15 at 01:36
  • for zsh braceccl is from 92, {1..5} from 95, {a..z} from 2014. For ksh93, the feature is from 2005, but ksh93r which is the first including it was released in 2006. – Stéphane Chazelas Aug 21 '15 at 07:19