12 examples to use flower brackets in Linux

This is a small post on how to crate multiple files/folders, sequence generation with flower brackets in-order to save valuable time.

Creating empty files can be done with touch command. We will see how to create multiple files using this command in one shot

Example1: Create a file with name abc.txt

touch abc.txt

Example2: Create multiple files abc, cde, efg, hij, klm Share Image

touch  abc cde efg hij klm

Example3: How about creating 1 to 20 files, ie creating multiple files with one command. Its bit tedious job for an admin. Don't worry Linux provide us with some useful option with "Flower braces" to do expansion. Instead of writing below command

touch 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20

We can create 20 files using flower brace {} exapantion as shown below..

touch {1..20}

Your shell tries to expand this brace and generate 1 to 20 numbers. The above command will create total 20 files in one shot.

Example4: How about creating files as 1.txt, 2.txt, 3.txt up to 1000.txt. This can be achieved suffixing it after brackets as shown below.

touch {1..1000}.txt

Example5: how about creating a1, a2, a3 so on up to a1000 files?

touch a{1..1000}

Example6:How about generating numbers?. We can generate numbers using flower braces with echo command. The other way to generate numbers is seq command.

echo {1..10}

Example7: Even we can do sequence for alphabets as shown below

touch {a..z}

Example8: Generate files from A to Z

touch {A..Z}

Note: The above alphabets generation is done using asci values

Example9: How about creating 1 to 1000000 files in one shot, by using multiplication/matrix of numbers?. We can achieve this one with multiplying two sequences.

touch {0..1000}{0..1000}

Example10: How about creating files as multiples of 2.

touch {1..100..2}

this will create files as 1, 3, 5, 7, 9, 11 etc.

Note: This interval will work only bash version 4.0 and above, make a note about this.

Example11: How about creating files as multiples of 7?

touch {1..100..7}

Note: This interval option will work only bash version 4 and above.

Practical usage of this brackets

1)In bash for loop.

2)Generating sequence of numbers.

As mention in above examples we can create folders similarly in one shot. use -p option if you want to create folders in sub folders too.

Example12: Create a folder structure as 2012, under this i want to create 12 folders for each month and under each month create 30 folders which corresponding to 30 days.

mkdir -p 2012/{1..12}/{1..30}
	This will create folder 2012 under that 1 to 12 folders and under each of these folders 1 to 30 folders in one go. Please feel free to comment your thoughts on this.
Show your love by sharing this..!
Share on VKShare on StumbleUponShare on YummlyPrint this pageFlattr the authorShare on TumblrEmail this to someoneBuffer this pageShare on Google+Share on LinkedInShare on FacebookTweet about this on TwitterPin on PinterestShare on RedditDigg this
The following two tabs change content below.
My name is Surendra Kumar Anne. I hail from Vijayawada which is capital of south Indian state of Andhra Pradesh. I am a Linux evangelist who believes in Hard work, A down to earth person, Likes to share knowledge with others, Loves dogs, Likes photography. I work with ICE systems, Sydney as Sr. Consultant. You can contact me at surendra (@) linuxnix dot com.

  • airbender

    Cool. So good to know these 😀

  • picky

    “flower brackets”? Do you mean “braces”, the name used in ISO-8859-1 for the characters “{” and “}”?

  • Subrat N

    Simply superb….

  • http://NA Saurav Srivastava

    Thank you for solving my query , you are really awesome

  • http://gravatar.com/design67 design67

    I saw someone do something like this touch !!:2/{package.json, index.js}
    and it created a package.json and index.js if 4 directories
    when I try it I’m getting an error. do I need some type of plugin

    • no

      It's refering to history '!'

      !! means last command

      !!:2 or !:2 means 2nd argument from the last command

      I imagine they needed to create a file in the directory which they'd just created in the previous command.

      Like below:

      ~/user$ mkdir test test2
      ~/user$ touch !:2/{1,2,3}
      touch test2/{1,2,3}


      ~/user$ ls -al test2/
      total 64
      drwxr-xr-x  2 user     user       0 Sep 18 16:20 .
      drwxrwxrwx 2 user user         0 Sep 18 16:20 ..
      -rw-r–r–  1 user     user          0 Sep 18 16:20 1
      -rw-r–r–  1 user     user          0 Sep 18 16:20 2
      -rw-r–r–  1 user     user          0 Sep 18 16:20 3

  • TD Murthy

    Thnaks all my questions about creation of files in one go answered here