A Cool Way to Create Multiple Files for your Project in WSL/WSL2

TL:DR — Batch create files with the Linux “touch” command

RamaDevsign (Rama Ochieng)
4 min readApr 1, 2021

For a long time now, Linux users seemed to have the upper hand when it comes to software development(with solid reasons to back them). But with the introduction of the now popular WSL (Windows Subsystem for Linux) , us windows folk have a reason to smile in regards to software development.

Today I’m not going to dive so much into the advantages of using Linux in software development, I want to share an interesting and cool way to create multiple files inside your Linux environment with the touch command.

The Touch command

The touch command is a standard command used in Linux based operating systems and it is used to create a file without any content ¹ .

The above code results in the creation of an empty index.ts file

Creating Multiple files

The same touch command can be used to create multiple files inside your project folder

The above code will result in the creation of an empty db.js file, an empty users.tsx file and an empty auth.ts file inside your current folder.

Leveling up inside the Linux terminal Matrix

If you have ever run into a task that requires the creation of multiple files of the same extension, it reaches a point where it gets too repetitive and that’s what happened to me a while back when creating files in a previous project. The file extension was .graphql and creating 10 files with such a long extension was getting repetitive and boring. As a developer I knew that there was a better and easier way to do it.

Introducing the brace expansion command. This is a handy bash feature that allows you to create long lists of arbitrary string combinations. More info on this can be found on this Bash Hackers Wiki article

The above code will result in the creation of 10 LOG files serially numbered and prefixed with the acc name

Now in my particular scenario, I wanted an easier way to create 10 files with the .graphql extension. My final resolve was to use the brace expansion command and type out all the file names in one instance then assign the files with the .graphql extension as shown below.

The above code resulted in my expected result of 10 files with a .graphql extension

This worked to my satisfaction and was a deserved win from my google research session. All the tabs that were open during the research can now be closed

In conclusion, there are a lot of tasks that can be achieved with the brace expansion command that I have not touched on and that are efficient and effective in your day to day coding activities.

The article on the Brace Expansion command dives deep into the many scenarios that might come in handy when using it in your tasks. I highly recommend that you have a look at it.

Thank you for reaching the end and kindly leave a clap if you found this article insightful. What are you planning to do with your new found Linux super power?

--

--

RamaDevsign (Rama Ochieng)

I am a software developer creating beautiful experiences on the web. Co-organizer: Reactjs Developer Community Kenya ||