Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Tested this on CentOS and Ubuntu, if you're in a directory with a ton of files

$ ls
day1.tar.gz  day2.tar.gz  day3.tar.gz  day4.tar.gz  day5.tar.gz  day6.tar.gz  day7.tar.gz  day8.tar.gz day9.tar.gz day10.tar.gz

And you hit Alt+Shift+{ it will awk-complete every filename

<Alt+Shift+{>

completes to:

 day{1{0.tar.gz,.tar.gz},2.tar.gz,3.tar.gz,4.tar.gz,5.tar.gz,6.tar.gz,7.tar.gz,8.tar.gz,9.tar.gz}

and

day1<Alt+Shift+{>

completes to:

day1{0.tar.gz,.tar.gz}

Questions: What is this? What is this called? Where is it useful? How can I configure it? Can I do this with for files that end with a substring not begin with one?

share|improve this question
add comment

1 Answer

up vote 9 down vote accepted

In Bash, it performs the readline function complete-into-braces.

Brace expansion is a useful way of abbreviating a reference to multiple files.

For example:

ls -l /path/to/dir/*.{c,h}

would list all the files that end in ".c" or ".h".

From man bash:

complete-into-braces (M-{)
Perform filename completion and insert the list of possible com‐ pletions enclosed within braces so the list is available to the shell (see Brace Expansion above).

and

Brace Expansion
Brace expansion is a mechanism by which arbitrary strings may be generated. This mechanism is similar to pathname expansion, but the filenames generated need not exist. Patterns to be brace expanded take the form of an optional preamble, followed by either a series of comma-separated strings or a sequence expression between a pair of braces, followed by an optional postscript. The preamble is prefixed to each string contained within the braces, and the postscript is then appended to each resulting string, expanding left to right.

Brace expansions may be nested. The results of each expanded string are not sorted; left to right order is preserved. For example, a{d,c,b}e expands into `ade ace abe'.

Completion, by definition, completes so it works with files that begin with a string.

share|improve this answer
    
I'm amazed.. It is an inverse brace expansion! ... Good one ;) ... –  Peter.O Feb 22 '11 at 9:03
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.