I have 700 directories at one location and I need to rename them using a .csv file as shown below:
I want to replace names of Column_A with the entries of Column_B.
Column_A Column_B
F001 IC500
F003 IC501
F006 IC502
F008 IC503
... ...
How do I batch rename the directories?
Best Answer
First export your data as .csv file format like below:
Then run the below script to rename those directories to their new names:
read -a
used for splitting each line read into array based fromIFS
which I redefined that to comma,
.Each line reads into
dirName
variable.${dirName[0]}
we are getting the first part of the line(column A).With
${dirName[1]}
we are getting the last part of the line(column B).mv
command used for rename there.So with
mv -v "/singleFolder/${dirName[0]}" "/singleFolder/${dirName[1]}"
, we are renaming the name of directories from columnA to new-name in columnB which are located insingleFolder
directory.-v
option shows what is being done during running the command.Also you can use the command without making the content of line as an array like this:
Note: remove
echo
command to performing rename on your real directories.