新聞中心
Nowadays, linux is widely used in our daily life and work. Releasing users from managing files through tedious mouse clicks, Linux has provided great convenience for us to manage files. Especially in the case of renaming multiple files, using Linux commands to conduct batch operation for our applications is a really effective way.

Take the case of using Linux to rename pictures as an example. Suppose we have a folder containing multiple pictures whose names are in a chaotic pattern. We can use the following command to easily rename them “image_1.jpg”, “Image_2.jpg” and so on.
`cd`
`for i in {1..50} ; do mv Image.jpg Image_${i}.jpg; done`
Basically, what this command does is looping through “1 to 50” and use “mv” attribute to execute the renaming process while substituting the suffix “Image_${i}.jpg”.
But if we want to go further and customize the naming pattern, and also avoid name conflicts (e.g., Image_2.jpg already exists), we may need more complex commands:
`ls|grep “Image”|cut -d “.” -f 1|xargs -I file num=`ls|grep “Image”|grep -c “^file”`; mv file.jpg Image_${num}.jpg`
The command is composed of different segments.
`ls` is used to check all the files in the current folder, `grep “Image”` is to limit the names of files to “Image” and `cut -d “.” -f 1` is to get rid of suffix.
`xargs` converts the output of “l(fā)s|grep “Image”” as the input parameter of “num=`ls|grep “Image”|grep -c “^file”`”, which is used to generate a number after “Image_”.
At last, `mv file.jpg Image_${num}.jpg` is to complete the renaming process.
By carrying out the commands above, we can easily customize the naming patterns for our files and make them in order without conflicts. Hope this article has offered you a good insight into the way of using Linux to rename multiple files.
香港服務(wù)器選創(chuàng)新互聯(lián),2H2G首月10元開通。
創(chuàng)新互聯(lián)(www.cdcxhl.com)互聯(lián)網(wǎng)服務(wù)提供商,擁有超過10年的服務(wù)器租用、服務(wù)器托管、云服務(wù)器、虛擬主機(jī)、網(wǎng)站系統(tǒng)開發(fā)經(jīng)驗(yàn)。專業(yè)提供云主機(jī)、虛擬主機(jī)、域名注冊(cè)、VPS主機(jī)、云服務(wù)器、香港云服務(wù)器、免備案服務(wù)器等。
新聞名稱:使用Linux批量重命名文件(批量重命名linux)
地址分享:http://m.5511xx.com/article/ccsgpee.html


咨詢
建站咨詢
