我想按照新名称列表重命名我的目录。
我想知道我是否可以利用以下命令来重命名位于同一主目录中的一组目录。
find . -type d -name 'thefoldername*' -exec mv {} newfoldername \;
实际目录名称是:
Actual_folder_names=['archery','benchpressing','bikingthroughsnow','blowingoutcandles','bowling','brushingteeth','cleanandjerk','divingcliff','drummingfingers','golfchipping','golfdriving']
改成 :
new_folder_name=['Archery' ,'BenchPress' ,'Biking' ,'BlowingCandles' ,'Bowling' ,'BrushingTeeth','CleanAndJerk' ,'Diving' ,'Drumming'
,'GolfSwing1', 'GolfSwing2']
谢谢
答案1
您只需将两个名称列表放入文本文件中即可进行重命名,如下所示:
创建两个列表
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
将两个列表并排放置,并在“试运行”模式下完成作业
paste listorig listdest | awk '{print "mv " $0}'
如果检查结果良好,就真的去做这项工作了:
paste listorig listdest | awk '{print "mv " $0}' |sh
工作完成了:)