Bash Brace Expansion

Quickly create and remove directory structures, rename, copy, or remove files with brace expansion.

Quickly Backing Up A File

The command below will produce a copy of filename.php to filename.php.back.

$ cp path/to/filename.php{,.back}

Is equivalent to:

$ cp path/to/filename.php path/to/filename.php.back

Create An Entire Directory Structure With One Command

The command line below will create the following directories:

  ./system
      /application
        /lib
        /controllers
        /models

$ mkdir -p system/application/{lib,controllers,models}/

Remove Several Files

Both of these methods will remove file[1-3].php.

$ rm {file1,file2,file3}.php

or

$ rm file{1,2,3}.php