Ubuntu16.04 (other versions can also be used) Batch modify the image name --- shell programming,
In windows, there are many easy-to-use image sorting software that can be used to sort images in batches. However, in ubuntu, you can write only one shell script to sort images and write shell code. The procedure is as follows.
(1 ),Create a rename. sh file. sh, which is usually placed in the directory where the image set is located), and then write the following code into the file (the meaning of each code has been marked in the Code ):
#! Test-folder/bash tells the file to be a shell script # mkdir images (you can create a folder like this and use the cp command to put the modified image in this folder) # output description of this file echo "this script is to rename picture" # Set the sequence variable for starting the image (I want to sort the image name from 70884) I = 70884 # names is an index of the image set to be modified (which can be set to any value ),. /name49/* indicates all the images in the names49 folder (you can change them to the location of your image set) for names in. /names49/* do # The Name Of The output image names is a variable. $ names indicates the content that references this variable echo $ names # variable assignment, news is a new variable news = $ I echo "$ news" # Change (if you change the mv to cp, copy the image with a higher name to the specified directory) the current image is recorded in the specified directory and named news.jpg mv $ names. /names49/w.news.jpg let I = I + 1 done
(2 ),The overall code and command execution are as follows (for ease of viewing and changing ):
Overall code:
#!test-folder/bash echo "this script is to rename picture" i=70884 for names in ./names49/* do echo $names news=$i echo "$news" mv $names ./names49/$news.jpg let i=i+1 done
Open the terminal in the current directory and run the following command:
sudo sh ./rename.sh
Note: When running this script, you may prompt "let: not found" because the above Code contains the "let" command. By default, the sh command is dash, while the dash command does not support the let Command. Therefore, use the bash command to display the command.
Changed:
sudo bash rename.sh
If you still want to use sudo sh./rename. sh, you must modify/bin/sh to point to bash. You can execute the following command:
sudo dpkg-reconfigure dash
A dialog box is displayed:
From the text on the image, we can see that using dash can improve the overall system performance, so it is best not to modify it. After modification, you can also use the same command as above to modify it. (Some keywords such as let and bash are supported, but sh and dash are not supported. For some keywords, select bash .)