Overview

Last time I showed you how to create a file in Linux, both ways – using text editors and using almighty terminal(link to »>POST«<). But, did you know that you can create multiple files at once? No, I don’t mean by repeating the same command over and over. I mean creating multiple files at once, with a single command.

So that’s, what are going to cover in this article - how to create multiple files in Linux with one command. On a similar topic we also covered how you can create multiple directories in Linux with one command - link to »>POST«<, and how to delete folders and files in Linux too - link to »>POST«<.

Create multiple files in Linux using TOUCH command

First, let’s recall touch command to create a single file:

touch newfile

Now before we continue it would be better to create a new directory, so you can easily delete all new created files.

mkdir testdir
and
cd testdir

Create multiple files in Linux

It’s time to see some magic at work. To create multiple files at once in terminal, you use touch command in this form:

touch newfilename{1..N}

So, if you want let’s say 5 files, just type

touch file{1..5}

Voila!

Create multiple files in Linux

Wanna go bigger? Peace of cake

touch newfile{1..10}

Create multiple files in Linux

Works like a charm.

Thinking of something specific, like html files? Or maybe php? Python perhaps? Yup, it’s all doable.

touch index.html{1..15}
touch somephp.php{1..20}
touch maybepython.py{1..50}
touch javascript.js{1..25}

And it’s all there.

Create multiple files in Linux

Thinking bigger? You can set limit to {1..100}. Wanna go higher than that? You can, but - commands like touch (also applicable to mv, rm and some other commands) have a certain limitations of accepting arguments depending of available stack size. And let’s be honest, who really needs 10k or more files to be created? But the question remains – is it doable? Why, yes it is!

*** WARNING!!! ***

Just a little heads up. If you do fall into temptation to play with high numbers, I strongly advice you not to. While 1k and 10k of files will somehow be done, do not try to play with 1mil. It’s a certain way to kill your computer or in best case scenario you’ll degrade the state of your system and hard drives. If you still have some sadistic desire to see that in works, you’re on your own. Can’t say you haven’t been warned.

Create multiple file in Linux using for loops

Now, where was I? Oh, yes, the other way of creating multiple files, but with just a little pinch of programming. You’re about to learn how to use “for loop” for that matter. Even if you have 0 experience in that field, it’s not that hard to grasp the concept. It goes like this:

for i in {1..100}; do touch filename$i.ext; done

where instead of “filename” you enter however you wish your files to be names, and instead of “.ext” you enter an extention of your choosing (whether is .txt, .html, .php,…).

Summary

Let’s recap - we demonstrated multiple steps on how to create multiple files in Linux with a single command, how to create multiple various file types and even with “for loops”, and with that we came to an end of this tutorial.

Thank you for your time… See ya next time!