[SHELL-SCRIPT] A Linux Shell Script to create a folder with a specific name under all sub-directories of a parent folder

By | 04th Jan 2013 | 1 min read

This is a script to create a particular directory under all subdirectories in a parent directory. Consider the case when a parent directory consists of more than 100 folders and you want create a new folder under all these directories, with the same name. Doing this manually would be a mess. This script would help you do this in no time.

These are the steps for executing the script:

First, add the exact path where the parent directory is present, and the name of the folder that is to be created.

Then, either pass the output of the 'ls' command as input to the script or pass the output of the 'ls' command to a text-file and pass this text-file as input to the script.

Now, copy the following script code into a file and save it with a .sh file extension after making the necessary changes to suit your needs.

Then run the script in terminal by typing './' infront of the name of the script.

For example, if the name of the script is 'create-directory.sh', you can run the script by typing './create-directory.sh'.

This will create the specific-directory for you.

#!/bin/bash
#Script to create a specific-directory on all subfolders in a parent-directory

path=/path/to-the/parent/directory

while read project
do
  echo "$foldersname"
  cd $path/$foldername/
  mkdir Folder-name-to-be-created
done < foldername.txt