0

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

5
  • How should the computer know where to capitalize? You want to move brushingteeth to BrushingTeeth, but how should it know where to put upper case letters?
    – redfast00
    Jan 23, 2018 at 15:30
  • for that case l can do it manually l just have few of them. Just ignore this case
    – Joseph
    Jan 23, 2018 at 15:32
  • Where do these names come from? what language are you trying to do this in (your list syntax looks pythonesque)? Jan 23, 2018 at 15:41
  • yes they are in python format. They represent names of data
    – Joseph
    Jan 23, 2018 at 15:44
  • So why not do it inside python (using zip to iterate over the lists pairwise + os.rename)? Jan 23, 2018 at 16:13

1 Answer 1

1

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 :)

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .