windows10 linux subsystem batch modify file name

Today there are a few suffix jpg batch of images need to modify the name

View all First name:

-rwxrwxrwx 1 michael michael       0 Jan 15  14 : 21   goo01
 -rwxrwxrwx 1 michael michael       0 Jan 15  14 : 23   goo02
 -rwxrwxrwx 1 michael michael       0 Jan 15  14 : 23   goo03
 -rwxrwxrwx 1 michael michael 431 898 Jan 15  10 : 39  ' 满意度2020-01-15_10.jpg ' 
-rwxrwxrwx 1 michael michael431 613 Jan 15  10 : 39  ' satisfaction 2020-01-15_11.jpg ' 
-rwxrwxrwx . 1 Michael Michael 448 659 Jan 15  10 : 39  ' satisfaction 2020-01-15_12.jpg ' 
-rwxrwxrwx . 1 Michael Michael 430 719 Jan 15  10 : 39  ' satisfaction 2020-01-15_13.jpg ' 
-rwxrwxrwx . 1 Michael Michael 459 284 Jan 15  10 : 39  ' satisfaction 2020-01-15_14.jpg '
-rwxrwxrwx . 1 Michael Michael 453 341 Jan 15  10 : 39  ' satisfaction 2020-01-15_2.jpg ' 
-rwxrwxrwx . 1 Michael Michael 428 014 Jan 15  10 : 39  ' satisfaction 2020-01-15_3.jpg '

Because windows10 below, the reality is that many of the names are with the space , the name is displayed when there will be a single quote

If you go through the bad batch modified by for the following words will appear in this case, satisfaction and 2020-01-15_10.jpg become two lines

for i in ` LS *`; do  echo $ i; DONE 
goo01 
goo02 
goo03 
Satisfaction 
2020 - 01 - 15_10.jpg 
Satisfaction 
2020 - 01 - 15_11.jpg 
Satisfaction 
2020 - 01 - 15_12.jpg 
Satisfaction 
2020 - 01 - 15_13.jpg 
satisfaction 
2020 - 01 - 15_14.jpg 
satisfaction

To address this situation you can use the read line of the batch mode operation

$ LS * | the while the Read i; do  echo $ i; DONE 
goo01 
goo02 
goo03 
Satisfaction 2020 - 01 - 15_10.jpg 
Satisfaction 2020 - 01 - 15_11.jpg 
Satisfaction 2020 - 01 - 15_12.jpg 
Satisfaction 2020 - 01 - 15_13.jpg 
satisfaction 2020 - 01 -15_14.jpg

Then bulk edits mv, echo, sed, here to note that all the files needed to bring the quotation marks when referring, we all try to "Satisfaction" to "test"

 ls *|while read i; do mv \'$i\' \'`echo $i |sed "s#满意度#test#g"`\'; do
ne
mv: cannot stat "'goo01'": No such file or directory
mv: cannot stat "'goo02'": No such file or directory
mv: cannot stat "'goo03'": No such file or directory
mv: target "2020-01-15_10.jpg'" is not a directory
mv: target "2020-01-15_11.jpg'" is not a directory
mv: target "2020-01-15_12.jpg'" is not a directory
mv: target "2020-01-15_13.jpg'" is not a directory

But you will find an error, suggesting no such document, in windows10 it is in trouble, but this time you can eval to handle this situation

 ls *|while read i; do eval mv \'$i\' \'`echo $i |sed "s#满意度#test#g"`\
'; done
mv: 'goo01' and 'goo01' are the same file
mv: 'goo02' and 'goo02' are the same file
mv: 'goo03' and 'goo03' are the same file
mv: 'Attendance sheet .jpg' And ' sign table .jpg ' are The Same File

Tip the contents of the same document here is not what we want to modify our side just to test the "check list" to "test", let us look at all the files have finished the bulk edits

drwxrwxrwx 1 michael michael   4096 Jan 15 14:39  ./
drwxrwxrwx 1 michael michael   4096 Jan 15 14:14  ../
-rwxrwxrwx 1 michael michael      0 Jan 15 14:21  goo01*
-rwxrwxrwx 1 michael michael      0 Jan 15 14:23  goo02*
-rwxrwxrwx 1 michael michael      0 Jan 15 14 : 23   goo03 * 
-rwxrwxrwx 1 michael michael 431898 Jan 15  10 : 39  ' test 2020-01-15_10.jpg ' * 
-rwxrwxrwx 1 michael michael 431613 Jan 15  10 : 39  ' test 2020-01-15_11.jpg ' * 
- rwxrwxrwx 1 michael michael 448659 Jan 15  10 : 39  ' test 2020-01-15_12.jpg ' * 
-rwxrwxrwx 1 michael michael430719 Jan 15 10:39 'test 2020-01-15_13.jpg'*
-rwxrwxrwx 1 michael michael 459284 Jan 15 10:39 'test 2020-01-15_14.jpg'*

eval series of parameters may be read, then the characteristic parameters is performed by itself.

The eval command linux can refer to this tutorial: https://www.runoob.com/linux/linux-comm-eval.html

Guess you like

Origin www.cnblogs.com/zmichael/p/12196668.html