bash批量重命名、批量更改后輟的方法
更新時間:2014年05月07日 09:30:16 作者:
這篇文章主要介紹了bash批量重命名、批量更改后輟的方法,需要的朋友可以參考下
用特定的格式重命名當前目錄的圖像文件,腳本如下:
#!/bin/bash
#Filename:rename_photo.sh
set -x
count=1
for img in *.jpg *.png
do
new=image-$count.${img##*.}
mv "$img" "$new" 2> /dev/null
if [ $? -eq 0 ]
then
echo "Renameing $img to $new"
let count++
fi
done
其他的執(zhí)行重命名的命令:rename
[root@localhost script]# rename image photo image*
將當前目錄下所有以image開頭的文件,換成以photo開關
[root@localhost rename]# ls
image_1.jpg image_2.jpg image_3.jpg image_4.jpg image_5.jpg
[root@localhost rename]# rename image photo image*
[root@localhost rename]# ls
photo_1.jpg photo_2.jpg photo_3.jpg photo_4.jpg photo_5.jpg
將擴展名小寫的.jpg改為大寫.JPG
[root@localhost rename]# rename .jpg .JPG *.jpg
[root@localhost rename]# ls
photo_1.JPG photo_2.JPG photo_3.JPG photo_4.JPG photo_5.JPG
復制代碼 代碼如下:
#!/bin/bash
#Filename:rename_photo.sh
set -x
count=1
for img in *.jpg *.png
do
new=image-$count.${img##*.}
mv "$img" "$new" 2> /dev/null
if [ $? -eq 0 ]
then
echo "Renameing $img to $new"
let count++
fi
done
其他的執(zhí)行重命名的命令:rename
復制代碼 代碼如下:
[root@localhost script]# rename image photo image*
將當前目錄下所有以image開頭的文件,換成以photo開關
[root@localhost rename]# ls
image_1.jpg image_2.jpg image_3.jpg image_4.jpg image_5.jpg
[root@localhost rename]# rename image photo image*
[root@localhost rename]# ls
photo_1.jpg photo_2.jpg photo_3.jpg photo_4.jpg photo_5.jpg
將擴展名小寫的.jpg改為大寫.JPG
[root@localhost rename]# rename .jpg .JPG *.jpg
[root@localhost rename]# ls
photo_1.JPG photo_2.JPG photo_3.JPG photo_4.JPG photo_5.JPG
您可能感興趣的文章:
相關文章
Shell腳本命令行批處理bash?sh?cmd?bat函數極簡學法
這篇文章主要為大家介紹了Shell腳本中文英文多語言國際化和命令行批處理(bash?sh?cmd?bat)中定義函數的簡單寫法示例詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助2023-09-09linux軟件版本管理命令update-alternatives使用詳解
這篇文章主要介紹了linux軟件版本管理命令update-alternatives使用詳解的相關資料,需要的朋友可以參考下2017-04-04