Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
165 views
in Technique[技术] by (71.8m points)

How to rename 400 directories in bash using new directory name stored in sql table

i have 400 directories which i wish to rename from old name to new name, i have both old name and new name in a sql table.

The old names are like this:

  • directory1
  • directory2
  • directory3

The new names will be like this as they will be a title of a pictures album which will be seen by a site visitors:

  • The directory 1
  • The directory 2
  • The directory 3

I plan to export all new and old names to a text file. I can make a 'source' file with old names and a 'target' file with new names, or i can make one file with old and new names comma separated. As my bash scripting knowledge is very poor i don't know how to achieve this Thank you

Old names example

directory1
directory2
directory3
directory4
directory5
directory6
directory7
directory8
directory9
directory10
directory11
directory12

New names example

'The directory 1'
'The directory 2'
'The directory 3'
'The directory 4'
'The directory 5'
'The directory 6'
'The directory 7'
'The directory 8'
'The directory 9'
'The directory 11'
'The directory 11'
'The directory 12'
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

If, with SQL, you can extract a file with old and new directory names with the following format:

% cat extractfile
mv 'directory1' 'The Directory 1'
mv 'directory2' 'The Directory 2'
mv 'directory3' 'The Directory 3'

Then all you need to do is to execute that file:

% bash extractfile

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...