Bash batch rename, batch change suffix method _linux shell

Source: Internet
Author: User
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
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.