How can l rename a set of directories given the list of new names?

Tags:

Answer: 1

31 hours ago

l would like to rename my directories following a list of new names.

l am wondering hoc can l take advantage of using the following command to rename a set of directories which are in the same principal directory.

find . -type d -name 'thefoldername*' -exec mv {} newfoldername \;

The actual directory names are :

Actual_folder_names=['archery','benchpressing','bikingthroughsnow','blowingoutcandles','bowling','brushingteeth','cleanandjerk','divingcliff','drummingfingers','golfchipping','golfdriving']

change to :

new_folder_name=['Archery' ,'BenchPress' ,'Biking' ,'BlowingCandles' ,'Bowling' ,'BrushingTeeth','CleanAndJerk' ,'Diving' ,'Drumming'
,'GolfSwing1', 'GolfSwing2']

Thank you

Answer: 2

18 hours ago

You can just put the two lists of names in text files to do the renaming like this :

Create the two lists

echo "'archery','benchpressing','bikingthroughsnow','blowingoutcandles','bowling','brushingteeth','cleanandjerk','divingcliff','drummingfingers','golfchipping','golfdriving'" |sed -e "s/'//g ; s/,/\n/g" > listorig
echo "'Archery' ,'BenchPress' ,'Biking' ,'BlowingCandles' ,'Bowling' ,'BrushingTeeth','CleanAndJerk' ,'Diving' ,'Drumming','GolfSwing1', 'GolfSwing2'" |sed -e "s/'//g ; s/,/\n/g" > listdest

Put the two lists side by side and do the job in "Dry run" mode

paste listorig listdest | awk '{print "mv " $0}'

If the check is good, really do the job :

paste listorig listdest | awk '{print "mv " $0}' |sh 

And the job is done :)

Added by: Talia Gusikowski

Popular Search

A B C D E F G H I J K L M N O P Q R S T U V W X Y Z 1 2 3 4 5 6 7 8 9