Shell script to rename a specific-directory present under all sub-directories in a specified parent folder

| | 1 min read

The function of the script is to rename a specific-directory present under all sub-directories of a specified parent folder. Consider, you have a particular folder under all sub-directories of a folder and you want to rename all of those occurrences. Doing it manually would take much time. Here is a script to make it easy for you.

The script takes the following inputs:
'path' is the absolute path of the parent folder, and
'foldername.txt' is a text file which contains the names of the subdirectories under each of which the specific directory has to be renamed.

Now save the script with any name of your choice and run it from the terminal to see it do what it was made to do. :-)

#!/bin/bash
#Script to rename a specific-directory present under all sub-directories in a specified parent folder

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

while read project
do
   echo "$foldersname"
   cd $path/$foldername/
   mv current-folder-name new-folder-name
done < foldername.txt