Renames the current directory's image file in a specific format, as follows:
Copy Code code as follows:
#!/bin/bash
#Filename: rename_photo.sh
Set-x
Count=1
For IMG in *.jpg *.png
Todo
new=image-$count. ${img##*.}
MV "$img" "$new" 2>/dev/null
If [$?-eq 0]
Then
echo "Renameing $img to $new"
Let count++
Fi
Done
Other commands to perform the renaming: rename
Copy Code code as follows:
[root@localhost script]# image Rename Photo
will have all files beginning with image in the current directory, Replace with the photo switch
[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.J pg photo_2.jpg photo_3.jpg photo_4.jpg photo_5.jpg
Changes the extension lowercase. jpg to uppercase. jpg
[ Root@localhost rename]# rename. jpg. JPG *.jpg
[root@localhost rename]# ls
photo_1.jpg photo_2.jpg photo_3.jpg photo_4.JPG p Hoto_5.jpg