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

TL:DR  -  Batch create files with the Linux "touch" command

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 ¹ .

01. touch command 1 large.jpg The above code results in the creation of an empty index.ts file

02. index_ts created.jpg

Creating Multiple files

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

03. the multiple files.jpg

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.

05. the created multiple files.jpg


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

06.brace in action.jpg The above code will result in the creation of 10 LOG files serially numbered and prefixed with the acc name

07.brace results.jpg 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.

08.touch gql command.jpg The above code resulted in my expected result of 10 files with a .graphql extension

09.touch gql result.jpg 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 like or a heart if you found this article insightful. What are you planning to do with your new found Linux super power?

Comments (1)

Deactivated User's photo

Thanks for the inspiration. I also read somewhere that to create large random file, command below might be useful:

dd if=/dev/urandom of=random.bin bs=1M count=1000

It can be used from within WSL on Windows 10 also.