Linux下批量修改文件名方法


對於在Linux中修改文件名的方式一般我們會用mv命令進行修改,但是mv命令是無法處理大量文件修改名稱。

但是在處理大量文件的時候該如何進行批量修改呢?

方法一:mv配合for循環方式進行修改

[root@show day74]# for name in `ls *.html`;do echo $name ${name%.html}.jpg;done
00.html 00.jpg
01.html 01.jpg
02.html 02.jpg
03.html 03.jpg
04.html 04.jpg
05.html 05.jpg
06.html 06.jpg
07.html 07.jpg
08.html 08.jpg
09.html 09.jpg
10.html 10.jpg
[root@show day74]# for name in `ls *.html`;do mv $name ${name%.html}.jpg;done
[root@show day74]# ls 
00.jpg 01.jpg 02.jpg 03.jpg 04.jpg 05.jpg 06.jpg 07.jpg 08.jpg 09.jpg 10.jpg

 

 

方法二:sed命令

ls *jpg|sed -r 's#(.*).jpg#mv &  \1.mp4#'|bash

方法三:rename命令

rename命令用字符串替換的方式批量改變文件名。

格式:rename  原名  替換名  要改的文件 

原字符串:將文件名需要替換的字符串; 目標字符串:將文件名中含有的原字符替換成目標字符串; 文件:指定要改變文件名的文件列表。

[root@cache01 test]# ls 
01.txt  03.txt  05.txt  07.txt  09.txt
02.txt  04.txt  06.txt  08.txt  10.txt
[root@cache01 test]# rename txt jpg *
[root@cache01 test]# ls 
01.jpg  03.jpg  05.jpg  07.jpg  09.jpg
02.jpg  04.jpg  06.jpg  08.jpg  10.jpg

有更多方法歡迎大家提出。

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM