How to create multiple files with the Terminal?

You can do this with these commands:

mkdir learning_c
cd learning_c
touch bspl{0001..0003}.c

Explanation:


  • mkdir learning_c

    • This will create a folder called learning_c in the current folder
    • The current folder usually is your home folder also called ~
    • You can change the current directory using the cd command (i.e. cd Desktop)
  • cd learning_c

    • Yes, you can guess it, you're entering on the newly created folder
  • touch bspl{0001..0003}.c

    • touch is a tool to create empty files and modify timestamps; we're creating empty files.
    • touch myfile will create an empty file called myfile.
    • The ugly code that follows (bspl{0001..0003}.c) is called a brace expansion. This is a great feature of the bash shell that allows you to create long lists of arbitrary string combinations. You can learn more about this in the Bash Hackers Wiki. In this case you will be making a long list of parameters that will be passed to touch. You can also use its long equivalent:

      touch bspl0001.c bspl0002.c bspl0003.c
      
    • You can change the number of files: if you want 12 files, you can run bspl{0001..0012}.c.

    • The leading zeros (0012 instead of 12) make sure that the output uses zero-padded 4 digits.

You can use the following python code, you can modify it to fit your needs.
Save the following code with filename filecreator.py

#!/usr/bin/env python
import os
import subprocess
work_path = os.path.abspath(os.path.dirname(__file__))
if not os.path.exists("learning_c"):
    os.mkdir("learning_c")
os.chdir(os.path.expanduser(work_path+"/learning_c"))
n = 10 #put the number as you wish
for i in range(n):
    subprocess.call(['touch', "bsdl"+str(i).zfill(4)+".c"])

And then execute it with this command:

python filecreator.py